~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_utextwrap.py

  • Committer: INADA Naoki
  • Date: 2011-05-08 16:11:56 UTC
  • mto: This revision was merged to the branch mainline in revision 5874.
  • Revision ID: songofacandy@gmail.com-20110508161156-d962p9m9gdszbdgu
Add keyword parameter 'ambiguous_width' that specifies width for character
when unicodedata.east_asian_width(c)=='A'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
class TestUTextWrap(tests.TestCase):
33
33
 
34
34
    def check_width(self, text, expected_width):
 
35
        w = utextwrap.UTextWrapper()
35
36
        self.assertEqual(
36
 
                utextwrap._width(text),
 
37
                w._width(text),
37
38
                expected_width,
38
39
                "Width of %r should be %d" % (text, expected_width))
39
40
 
40
 
    def test__width(self):
 
41
    def test_width(self):
41
42
        self.check_width(_str_D, 8)
42
43
        self.check_width(_str_SD, 13)
43
44
 
44
45
    def check_cut(self, text, width, pos):
45
 
        self.assertEqual((text[:pos], text[pos:]), utextwrap._cut(text, width))
 
46
        w = utextwrap.UTextWrapper()
 
47
        self.assertEqual((text[:pos], text[pos:]), w._cut(text, width))
46
48
 
47
49
    def test_cut(self):
48
50
        s = _str_SD
99
101
                                     "spam" + _str_D[:2],
100
102
                                     _str_D[2:]+_str_D[:2],
101
103
                                     _str_D[2:]]),
102
 
                utextwrap.fill(text, 8, break_long_words=False))
 
104
                         utextwrap.fill(text, 8, break_long_words=False))
103
105
 
104
106
    def test_fill_indent_with_breaks(self):
105
107
        w = utextwrap.UTextWrapper(8, initial_indent=' '*4,
134
136
                                     ]),
135
137
                         w.fill(_str_SD))
136
138
 
 
139
class TestUTextWrapAmbiWidth(tests.TestCase):
 
140
    _cyrill_char = u"\u0410" # east_asian_width() == 'A'
 
141
 
 
142
    def test_ambiwidth1(self):
 
143
        w = utextwrap.UTextWrapper(4, ambiguous_width=1)
 
144
        s = self._cyrill_char*8
 
145
        self.assertEqual([self._cyrill_char*4]*2, w.wrap(s))
 
146
 
 
147
    def test_ambiwidth2(self):
 
148
        w = utextwrap.UTextWrapper(4, ambiguous_width=2)
 
149
        s = self._cyrill_char*8
 
150
        self.assertEqual([self._cyrill_char*2]*4, w.wrap(s))
 
151
 
137
152
 
138
153
# Regression test with Python's test_textwrap
139
154
# Note that some distribution including Ubuntu doesn't install