~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-04 15:13:24 UTC
  • mto: This revision was merged to the branch mainline in revision 5874.
  • Revision ID: songofacandy@gmail.com-20110504151324-8yn9gu0u80jcyoho
Move tests for utextwrap from the module to bzrlib.tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2011 Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
#
 
17
 
 
18
"""Tests of the bzrlib.utextwrap."""
 
19
 
 
20
from bzrlib import tests, utextwrap
 
21
 
 
22
# Japanese "Good morning".
 
23
# Each character have double width. So total 8 width on console.
 
24
_str_D = u'\u304a\u306f\u3088\u3046'
 
25
 
 
26
_str_S = u"hello"
 
27
 
 
28
# Combine single width characters and double width characters.
 
29
_str_SD = _str_S + _str_D
 
30
_str_DS = _str_D + _str_S
 
31
 
 
32
class TestUTextWrap(tests.TestCase):
 
33
 
 
34
    def assertWidth(self, text, expected_width):
 
35
        self.assertEqual(
 
36
                utextwrap._width(text),
 
37
                expected_width,
 
38
                "Width of %r should be %d" % (text, expected_width))
 
39
 
 
40
    def test__width(self):
 
41
        self.assertWidth(_str_D, 8)
 
42
        self.assertWidth(_str_SD, 13)
 
43
 
 
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)
 
47
 
 
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)
 
51
 
 
52
        # word should be split between double width character and single
 
53
        # width character.
 
54
        self.assertEqual(utextwrap._break_cjkword(_str_DS, 10),
 
55
                         (_str_D, _str_S))
 
56
 
 
57
    def test_wrap(self):
 
58
        self.assertEqual(utextwrap.wrap(_str_D, 1), list(_str_D))
 
59
        self.assertEqual(utextwrap.wrap(_str_D, 2), list(_str_D))