Merge branch 'merge-no-commit'
[git-cola.git] / test / textwrap_test.py
blob90c0277f9ed0ea4f3f6a0f5742f02ad7e6068e48
1 #!/usr/bin/env python
2 from __future__ import unicode_literals
4 import unittest
5 from cola import textwrap
8 class WordWrapTestCase(unittest.TestCase):
9 def setUp(self):
10 self.tabwidth = 8
11 self.limit = None
13 def wrap(self, text):
14 return textwrap.word_wrap(text, self.tabwidth, self.limit)
16 def test_word_wrap(self):
17 self.limit = 16
18 text = """
19 12345678901 3 56 8 01 3 5 7
21 1 3 5"""
22 expect = """
23 12345678901 3 56
24 8 01 3 5 7
26 1 3 5"""
27 self.assertEqual(expect, self.wrap(text))
29 def test_word_wrap_dashes(self):
30 self.limit = 4
31 text = '123-5'
32 expect = '123-5'
33 self.assertEqual(expect, self.wrap(text))
35 def test_word_wrap_double_dashes(self):
36 self.limit = 4
37 text = '12--5'
38 expect = '12--\n5'
39 self.assertEqual(expect, self.wrap(text))
41 def test_word_wrap_many_lines(self):
42 self.limit = 2
43 text = """
47 bb cc dd"""
48 expect = """
54 dd"""
55 self.assertEqual(expect, self.wrap(text))
57 def test_word_python_code(self):
58 self.limit = 78
59 text = """
60 if True:
61 print "hello world"
62 else:
63 print "hello world"
65 """
66 self.assertEqual(text, self.wrap(text))
68 def test_word_wrap_spaces(self):
69 self.limit = 2
70 text = ' ' * 6
71 self.assertEqual(' ' * 6, self.wrap(text))
73 def test_word_wrap_special_tag(self):
74 self.limit = 2
75 text = """
76 This test is so meta, even this sentence
78 Cheered-on-by: Avoids word-wrap
79 C.f. This also avoids word-wrap
80 References: This also avoids word-wrap
81 See-also: This also avoids word-wrap
82 Related-to: This also avoids word-wrap
83 Link: This also avoids word-wrap
84 """
86 expect = """
87 This
88 test
91 meta,
92 even
93 this
94 sentence
96 Cheered-on-by: Avoids word-wrap
97 C.f. This also avoids word-wrap
98 References: This also avoids word-wrap
99 See-also: This also avoids word-wrap
100 Related-to: This also avoids word-wrap
101 Link: This also avoids word-wrap
104 self.assertEqual(self.wrap(text), expect)
106 def test_word_wrap_space_at_start_of_wrap(self):
107 inputs = """0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 """
108 expect = """0 1 2 3 4 5 6 7 8 9\n0 1 2 3 4 5 6 7 8"""
109 self.limit = 20
110 actual = self.wrap(inputs)
111 self.assertEqual(expect, actual)
114 if __name__ == '__main__':
115 unittest.main()