~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_utextwrap.py

  • Committer: Vincent Ladeuil
  • Date: 2011-05-05 06:55:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5874.
  • Revision ID: v.ladeuil+lp@free.fr-20110505065535-s4nfj4rnkdshewyr
Use assert(expected, actual) style and split some tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
        self.check_width(_str_SD, 13)
43
43
 
44
44
    def check_cut(self, text, width, pos):
45
 
        self.assertEqual(
46
 
                utextwrap._cut(text, width),
47
 
                (text[:pos], text[pos:])
48
 
                )
 
45
        self.assertEqual((text[:pos], text[pos:]), utextwrap._cut(text, width))
49
46
 
50
47
    def test_cut(self):
51
48
        s = _str_SD
61
58
 
62
59
    def test_split(self):
63
60
        w = utextwrap.UTextWrapper()
64
 
        self.assertEqual(w._split(_str_D), list(_str_D))
65
 
        self.assertEqual(w._split(_str_SD), [_str_S]+list(_str_D))
66
 
        self.assertEqual(w._split(_str_DS), list(_str_D)+[_str_S])
 
61
        self.assertEqual(list(_str_D), w._split(_str_D))
 
62
        self.assertEqual([_str_S]+list(_str_D), w._split(_str_SD))
 
63
        self.assertEqual(list(_str_D)+[_str_S], w._split(_str_DS))
67
64
 
68
65
    def test_wrap(self):
69
 
        self.assertEqual(utextwrap.wrap(_str_D, 1), list(_str_D))
70
 
        self.assertEqual(utextwrap.wrap(_str_D, 2), list(_str_D))
71
 
        self.assertEqual(utextwrap.wrap(_str_D, 3), list(_str_D))
72
 
        self.assertEqual(utextwrap.wrap(_str_D, 3, break_long_words=False),
73
 
                list(_str_D))
 
66
        self.assertEqual(list(_str_D), utextwrap.wrap(_str_D, 1))
 
67
        self.assertEqual(list(_str_D), utextwrap.wrap(_str_D, 2))
 
68
        self.assertEqual(list(_str_D), utextwrap.wrap(_str_D, 3))
 
69
        self.assertEqual(list(_str_D),
 
70
                         utextwrap.wrap(_str_D, 3, break_long_words=False))
74
71
 
75
 
    def test_fill(self):
 
72
    def test_fill_simple(self):
76
73
        # Test only can call fill() because it's just '\n'.join(wrap(text)).
77
 
        self.assertEqual(utextwrap.fill(_str_D, 4),
78
 
                "%s\n%s" % (_str_D[:2], _str_D[2:]))
 
74
        self.assertEqual("%s\n%s" % (_str_D[:2], _str_D[2:]),
 
75
                         utextwrap.fill(_str_D, 4))
79
76
 
 
77
    def test_fill_with_breaks(self):
80
78
        # Demonstrate complicated case.
81
79
        text = u"spam ham egg spamhamegg" + _str_D + u" spam" + _str_D*2
82
 
        self.assertEqual(
83
 
                utextwrap.fill(text, 8),
84
 
                u'\n'.join([
85
 
                    "spam ham",
86
 
                    "egg spam",
87
 
                    "hamegg" + _str_D[0],
88
 
                    _str_D[1:],
89
 
                    "spam" + _str_D[:2],
90
 
                    _str_D[2:]+_str_D[:2],
91
 
                    _str_D[2:]
92
 
                    ]))
93
 
 
94
 
        self.assertEqual(
95
 
                utextwrap.fill(text, 8, break_long_words=False),
96
 
                u'\n'.join([
97
 
                    "spam ham",
98
 
                    "egg",
99
 
                    "spamhamegg", 
100
 
                    # border between single width and double width.
101
 
                    _str_D,
102
 
                    "spam" + _str_D[:2],
103
 
                    _str_D[2:]+_str_D[:2],
104
 
                    _str_D[2:]
105
 
                    ]))
106
 
 
107
 
    def test_fill_indent(self):
108
 
        w = utextwrap.UTextWrapper(8,
109
 
                initial_indent=' '*4, subsequent_indent=' '*4)
110
 
 
111
 
        self.assertEqual(w.fill(_str_SD),
112
 
                u'\n'.join([
113
 
                    "    hell",
114
 
                    "    o" + _str_D[0],
115
 
                    "    " + _str_D[1:3],
116
 
                    "    " + _str_D[3]
117
 
                    ]))
118
 
 
119
 
        w.break_long_words = False
120
 
 
121
 
        self.assertEqual(w.fill(_str_SD),
122
 
                u'\n'.join([
123
 
                    "    hello",
124
 
                    "    " + _str_D[:2],
125
 
                    "    " + _str_D[2:],
126
 
                    ]))
127
 
 
 
80
        self.assertEqual(u'\n'.join(["spam ham",
 
81
                                     "egg spam",
 
82
                                     "hamegg" + _str_D[0],
 
83
                                     _str_D[1:],
 
84
                                     "spam" + _str_D[:2],
 
85
                                     _str_D[2:]+_str_D[:2],
 
86
                                     _str_D[2:]]),
 
87
                         utextwrap.fill(text, 8))
 
88
 
 
89
    def test_fill_without_breaks(self):
 
90
        text = u"spam ham egg spamhamegg" + _str_D + u" spam" + _str_D*2
 
91
        self.assertEqual(u'\n'.join(["spam ham",
 
92
                                     "egg",
 
93
                                     "spamhamegg", 
 
94
                                     # border between single width and double
 
95
                                     # width.
 
96
                                     _str_D,
 
97
                                     "spam" + _str_D[:2],
 
98
                                     _str_D[2:]+_str_D[:2],
 
99
                                     _str_D[2:]]),
 
100
                utextwrap.fill(text, 8, break_long_words=False))
 
101
 
 
102
    def test_fill_indent_with_breaks(self):
 
103
        w = utextwrap.UTextWrapper(8, initial_indent=' '*4,
 
104
                                   subsequent_indent=' '*4)
 
105
        self.assertEqual(u'\n'.join(["    hell",
 
106
                                     "    o" + _str_D[0],
 
107
                                     "    " + _str_D[1:3],
 
108
                                     "    " + _str_D[3]
 
109
                                     ]),
 
110
                         w.fill(_str_SD))
 
111
 
 
112
    def test_fill_indent_without_breaks(self):
 
113
        w = utextwrap.UTextWrapper(8, initial_indent=' '*4,
 
114
                                   subsequent_indent=' '*4)
 
115
        w.break_long_words = False
 
116
        self.assertEqual(u'\n'.join(["    hello",
 
117
                                     "    " + _str_D[:2],
 
118
                                     "    " + _str_D[2:],
 
119
                                     ]),
 
120
                         w.fill(_str_SD))
 
121
 
 
122
    def test_fill_indent_without_breaks_with_fixed_width(self):
 
123
        w = utextwrap.UTextWrapper(8, initial_indent=' '*4,
 
124
                                   subsequent_indent=' '*4)
 
125
        w.break_long_words = False
128
126
        w.width = 3
129
 
 
130
 
        self.assertEqual(w.fill(_str_SD),
131
 
                u'\n'.join([
132
 
                    "    hello",
133
 
                    "    " + _str_D[0],
134
 
                    "    " + _str_D[1],
135
 
                    "    " + _str_D[2],
136
 
                    "    " + _str_D[3],
137
 
                    ]))
 
127
        self.assertEqual(u'\n'.join(["    hello",
 
128
                                     "    " + _str_D[0],
 
129
                                     "    " + _str_D[1],
 
130
                                     "    " + _str_D[2],
 
131
                                     "    " + _str_D[3],
 
132
                                     ]),
 
133
                         w.fill(_str_SD))
138
134
 
139
135
 
140
136
# Regression test with Python's test_textwrap