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_double_dashes(self
):
41 self
.assertEqual(expect
, self
.wrap(text
, break_on_hyphens
=True))
44 self
.assertEqual(expect
, self
.wrap(text
, break_on_hyphens
=False))
46 def test_word_wrap_many_lines(self
):
60 self
.assertEqual(expect
, self
.wrap(text
))
62 def test_word_python_code(self
):
71 self
.assertEqual(text
, self
.wrap(text
))
73 def test_word_wrap_spaces(self
):
76 self
.assertEqual(' ' * 6, self
.wrap(text
))
78 def test_word_wrap_special_tag(self
):
81 This test is so meta, even this sentence
83 Cheered-on-by: Avoids word-wrap
84 C.f. This also avoids word-wrap
85 References: This also avoids word-wrap
86 See-also: This also avoids word-wrap
87 Related-to: This also avoids word-wrap
88 Link: This also avoids word-wrap
101 Cheered-on-by: Avoids word-wrap
102 C.f. This also avoids word-wrap
103 References: This also avoids word-wrap
104 See-also: This also avoids word-wrap
105 Related-to: This also avoids word-wrap
106 Link: This also avoids word-wrap
109 self
.assertEqual(self
.wrap(text
), expect
)
111 def test_word_wrap_space_at_start_of_wrap(self
):
112 inputs
= """0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 """
113 expect
= """0 1 2 3 4 5 6 7 8 9\n0 1 2 3 4 5 6 7 8"""
115 actual
= self
.wrap(inputs
)
116 self
.assertEqual(expect
, actual
)
118 def test_word_wrap_ranges(self
):
119 text
= 'a bb ccc dddd\neeeee'
120 expect
= 'a\nbb\nccc\ndddd\neeeee'
121 actual
= textwrap
.word_wrap(text
, 8, 2)
122 self
.assertEqual(expect
, actual
)
124 expect
= 'a bb\nccc\ndddd\neeeee'
125 actual
= textwrap
.word_wrap(text
, 8, 4)
126 self
.assertEqual(expect
, actual
)
128 text
= 'a bb ccc dddd\n\teeeee'
129 expect
= 'a bb\nccc\ndddd\n\t\neeeee'
130 actual
= textwrap
.word_wrap(text
, 8, 4)
131 self
.assertEqual(expect
, actual
)
134 if __name__
== '__main__':