3 from __future__
import absolute_import
, division
, unicode_literals
6 from cola
import textwrap
9 class WordWrapTestCase(unittest
.TestCase
):
14 def wrap(self
, text
, break_on_hyphens
=True):
15 return textwrap
.word_wrap(text
, self
.tabwidth
, self
.limit
,
16 break_on_hyphens
=break_on_hyphens
)
18 def test_word_wrap(self
):
21 12345678901 3 56 8 01 3 5 7
29 self
.assertEqual(expect
, self
.wrap(text
))
31 def test_word_wrap_dashes(self
):
35 self
.assertEqual(expect
, self
.wrap(text
))
37 def test_word_wrap_leading_spaces(self
):
41 self
.assertEqual(expect
, self
.wrap('1234 5'))
42 self
.assertEqual(expect
, self
.wrap('1234 5'))
43 self
.assertEqual(expect
, self
.wrap('1234 5'))
44 self
.assertEqual(expect
, self
.wrap('1234 5'))
45 self
.assertEqual(expect
, self
.wrap('1234 5'))
48 self
.assertEqual(expect
, self
.wrap('123 4'))
49 self
.assertEqual(expect
, self
.wrap('123 4'))
50 self
.assertEqual(expect
, self
.wrap('123 4'))
51 self
.assertEqual(expect
, self
.wrap('123 4'))
52 self
.assertEqual(expect
, self
.wrap('123 4'))
54 def test_word_wrap_double_dashes(self
):
58 self
.assertEqual(expect
, self
.wrap(text
, break_on_hyphens
=True))
61 self
.assertEqual(expect
, self
.wrap(text
, break_on_hyphens
=False))
63 def test_word_wrap_many_lines(self
):
77 self
.assertEqual(expect
, self
.wrap(text
))
79 def test_word_python_code(self
):
88 self
.assertEqual(text
, self
.wrap(text
))
90 def test_word_wrap_spaces(self
):
93 self
.assertEqual('', self
.wrap(text
))
95 def test_word_wrap_special_tag(self
):
98 This test is so meta, even this sentence
100 Cheered-on-by: Avoids word-wrap
101 C.f. This also avoids word-wrap
102 References: This also avoids word-wrap
103 See-also: This also avoids word-wrap
104 Related-to: This also avoids word-wrap
105 Link: This also avoids word-wrap
118 Cheered-on-by: Avoids word-wrap
119 C.f. This also avoids word-wrap
120 References: This also avoids word-wrap
121 See-also: This also avoids word-wrap
122 Related-to: This also avoids word-wrap
123 Link: This also avoids word-wrap
126 self
.assertEqual(self
.wrap(text
), expect
)
128 def test_word_wrap_space_at_start_of_wrap(self
):
129 inputs
= """0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 """
130 expect
= """0 1 2 3 4 5 6 7 8 9\n0 1 2 3 4 5 6 7 8"""
132 actual
= self
.wrap(inputs
)
133 self
.assertEqual(expect
, actual
)
135 def test_word_wrap_keeps_tabs_at_start(self
):
136 inputs
= """\tfirst line\n\n\tsecond line"""
137 expect
= """\tfirst line\n\n\tsecond line"""
139 actual
= self
.wrap(inputs
)
140 self
.assertEqual(expect
, actual
)
142 def test_word_wrap_keeps_twospace_indents(self
):
143 inputs
= """first line\n\n* branch:\n line1\n line2\n"""
144 expect
= """first line\n\n* branch:\n line1\n line2\n"""
146 actual
= self
.wrap(inputs
)
147 self
.assertEqual(expect
, actual
)
149 def test_word_wrap_ranges(self
):
150 text
= 'a bb ccc dddd\neeeee'
151 expect
= 'a\nbb\nccc\ndddd\neeeee'
152 actual
= textwrap
.word_wrap(text
, 8, 2)
153 self
.assertEqual(expect
, actual
)
155 expect
= 'a bb\nccc\ndddd\neeeee'
156 actual
= textwrap
.word_wrap(text
, 8, 4)
157 self
.assertEqual(expect
, actual
)
159 text
= 'a bb ccc dddd\n\teeeee'
160 expect
= 'a bb\nccc\ndddd\n\t\neeeee'
161 actual
= textwrap
.word_wrap(text
, 8, 4)
162 self
.assertEqual(expect
, actual
)
165 if __name__
== '__main__':