cmds: provide $DIRNAME in the environment for guitool commands
[git-cola.git] / test / textwrap_test.py
blob0adb94f9ea06a6077c7f89cb644a6d4da7488c2e
1 #!/usr/bin/env python
3 from __future__ import absolute_import, division, unicode_literals
5 import unittest
6 from cola import textwrap
9 class WordWrapTestCase(unittest.TestCase):
10 def setUp(self):
11 self.tabwidth = 8
12 self.limit = None
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):
19 self.limit = 16
20 text = """
21 12345678901 3 56 8 01 3 5 7
23 1 3 5"""
24 expect = """
25 12345678901 3 56
26 8 01 3 5 7
28 1 3 5"""
29 self.assertEqual(expect, self.wrap(text))
31 def test_word_wrap_dashes(self):
32 self.limit = 4
33 text = '123-5'
34 expect = '123-5'
35 self.assertEqual(expect, self.wrap(text))
37 def test_word_wrap_double_dashes(self):
38 self.limit = 4
39 text = '12--5'
40 expect = '12--\n5'
41 self.assertEqual(expect, self.wrap(text, break_on_hyphens=True))
43 expect = '12--5'
44 self.assertEqual(expect, self.wrap(text, break_on_hyphens=False))
46 def test_word_wrap_many_lines(self):
47 self.limit = 2
48 text = """
52 bb cc dd"""
53 expect = """
59 dd"""
60 self.assertEqual(expect, self.wrap(text))
62 def test_word_python_code(self):
63 self.limit = 78
64 text = """
65 if True:
66 print "hello world"
67 else:
68 print "hello world"
70 """
71 self.assertEqual(text, self.wrap(text))
73 def test_word_wrap_spaces(self):
74 self.limit = 2
75 text = ' ' * 6
76 self.assertEqual(' ' * 6, self.wrap(text))
78 def test_word_wrap_special_tag(self):
79 self.limit = 2
80 text = """
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
89 """
91 expect = """
92 This
93 test
96 meta,
97 even
98 this
99 sentence
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"""
114 self.limit = 20
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__':
135 unittest.main()