1
# Copyright (C) 2011 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Tests of the bzrlib.utextwrap."""
20
from bzrlib import tests, utextwrap
22
# Japanese "Good morning".
23
# Each character have double width. So total 8 width on console.
24
_str_D = u'\u304a\u306f\u3088\u3046'
28
# Combine single width characters and double width characters.
29
_str_SD = _str_S + _str_D
30
_str_DS = _str_D + _str_S
32
class TestUTextWrap(tests.TestCase):
34
def assertWidth(self, text, expected_width):
36
utextwrap._width(text),
38
"Width of %r should be %d" % (text, expected_width))
40
def test__width(self):
41
self.assertWidth(_str_D, 8)
42
self.assertWidth(_str_SD, 13)
44
def test__break_cjkword(self):
45
self.assertEqual(utextwrap._break_cjkword(u"hello", 3), None)
46
self.assertEqual(utextwrap._break_cjkword(_str_D, 1), None)
48
half = _str_D[:2], _str_D[2:]
49
self.assertEqual(utextwrap._break_cjkword(_str_D, 4), half)
50
self.assertEqual(utextwrap._break_cjkword(_str_D, 5), half)
52
# word should be split between double width character and single
54
self.assertEqual(utextwrap._break_cjkword(_str_DS, 10),
58
self.assertEqual(utextwrap.wrap(_str_D, 1), list(_str_D))
59
self.assertEqual(utextwrap.wrap(_str_D, 2), list(_str_D))