doc: v1.9.2 release notes draft
[git-cola.git] / test / test_cola_textwrap.py
blob4bf451dd96f98fc853383855eaeea5915deef68a
1 #!/usr/bin/env python
3 import unittest
4 from cola import textwrap
7 class WordWrapTestCase(unittest.TestCase):
8 def setUp(self):
9 self.tabwidth = 8
10 self.limit = None
12 def wrap(self, text):
13 return textwrap.word_wrap(text, self.tabwidth, self.limit)
15 def test_word_wrap(self):
16 self.limit = 16
17 text = """
18 12345678901 3 56 8 01 3 5 7
20 1 3 5"""
21 expect = """
22 12345678901 3 56
23 8 01 3 5 7
25 1 3 5"""
26 self.assertEqual(expect, self.wrap(text))
28 def test_word_wrap_dashes(self):
29 self.limit = 4
30 text = '123-5'
31 expect = '123-5'
32 self.assertEqual(expect, self.wrap(text))
34 def test_word_wrap_double_dashes(self):
35 self.limit = 4
36 text = '12--5'
37 expect = '12--\n5'
38 self.assertEqual(expect, self.wrap(text))
40 def test_word_wrap_many_lines(self):
41 self.limit = 2
42 text = """
46 bb cc dd"""
47 expect = """
53 dd"""
54 self.assertEqual(expect, self.wrap(text))
56 def test_word_python_code(self):
57 self.limit = 78
58 text = """
59 if True:
60 print "hello world"
61 else:
62 print "hello world"
64 """
65 self.assertEqual(text, self.wrap(text))
67 def test_word_wrap_spaces(self):
68 self.limit = 2
69 text = ' ' * 6
70 self.assertEqual(' ' * 6, self.wrap(text))
72 def test_word_wrap_special_tag(self):
73 self.limit = 2
74 text = """
75 This test is so meta, even this sentence
77 With-special-tag: Avoids word-wrap
78 """
80 expect = """
81 This
82 test
85 meta,
86 even
87 this
88 sentence
90 With-special-tag: Avoids word-wrap
91 """
93 self.assertEqual(self.wrap(text), expect)
95 def test_word_wrap_space_at_start_of_wrap(self):
96 inputs = """0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 """
97 expect = """0 1 2 3 4 5 6 7 8 9\n0 1 2 3 4 5 6 7 8"""
98 self.limit = 20
99 actual = self.wrap(inputs)
100 self.assertEqual(expect, actual)
103 if __name__ == '__main__':
104 unittest.main()