Skip to content

Commit

Permalink
fix bug: line_break
Browse files Browse the repository at this point in the history
  • Loading branch information
restran committed Mar 22, 2018
1 parent 033c494 commit cec2436
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mountains/utils/string_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ def fixed_length_split(s, width):


def line_break(s, length=76):
x = '\n'.join(s[pos:pos + length] for pos in range(0, len(s), 76))
x = '\n'.join(s[pos:pos + length] for pos in range(0, len(s), length))
return x
37 changes: 37 additions & 0 deletions tests/test_string_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
# Created by restran on 2018/3/22
from __future__ import unicode_literals, absolute_import

from mountains.utils import string_utils
import unittest
import random
import string


class UtilsTest(unittest.TestCase):
def test_line_break(self):
s = ''.join([random.choice(string.ascii_letters + string.digits) for _ in xrange(3000)])
break_s = string_utils.line_break(s)
self.assertEqual(s, break_s.replace('\n', ''))

break_s = string_utils.line_break(s, 10)
self.assertEqual(s, break_s.replace('\n', ''))

break_s = string_utils.line_break(s, 100)
self.assertEqual(s, break_s.replace('\n', ''))

break_s = string_utils.line_break(s, 3001)
self.assertEqual(s, break_s.replace('\n', ''))

def test_fixed_length_split(self):
s = 'aaaabbbbccccdddd'
r = string_utils.fixed_length_split(s, 4)
self.assertEqual(r, ['aaaa', 'bbbb', 'cccc', 'dddd'])
r = string_utils.fixed_length_split(s, 6)
self.assertEqual(r, ['aaaabb', 'bbcccc', 'dddd'])
r = string_utils.fixed_length_split(s, 16)
self.assertEqual(r, ['aaaabbbbccccdddd'])


if __name__ == '__main__':
unittest.main()

0 comments on commit cec2436

Please sign in to comment.