~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

Fix bug in internal_diff handling of unicode paths

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
        udiff_lines([1023 * 'a' + '\x00'], [], allow_binary=True)
77
77
        udiff_lines([], [1023 * 'a' + '\x00'], allow_binary=True)
78
78
 
 
79
    def test_internal_diff_default(self):
 
80
        # Default internal diff encoding is utf8
 
81
        output = StringIO()
 
82
        internal_diff(u'old_\xb5', ['old_text\n'],
 
83
                    u'new_\xe5', ['new_text\n'], output)
 
84
        lines = output.getvalue().splitlines(True)
 
85
        self.check_patch(lines)
 
86
        self.assertEquals(['--- old_\xc2\xb5\t\n',
 
87
                           '+++ new_\xc3\xa5\t\n',
 
88
                           '@@ -1,1 +1,1 @@\n',
 
89
                           '-old_text\n',
 
90
                           '+new_text\n',
 
91
                           '\n',
 
92
                          ]
 
93
                          , lines)
 
94
 
 
95
    def test_internal_diff_utf8(self):
 
96
        output = StringIO()
 
97
        internal_diff(u'old_\xb5', ['old_text\n'],
 
98
                    u'new_\xe5', ['new_text\n'], output,
 
99
                    path_encoding='utf8')
 
100
        lines = output.getvalue().splitlines(True)
 
101
        self.check_patch(lines)
 
102
        self.assertEquals(['--- old_\xc2\xb5\t\n',
 
103
                           '+++ new_\xc3\xa5\t\n',
 
104
                           '@@ -1,1 +1,1 @@\n',
 
105
                           '-old_text\n',
 
106
                           '+new_text\n',
 
107
                           '\n',
 
108
                          ]
 
109
                          , lines)
 
110
 
 
111
    def test_internal_diff_iso_8859_1(self):
 
112
        output = StringIO()
 
113
        internal_diff(u'old_\xb5', ['old_text\n'],
 
114
                    u'new_\xe5', ['new_text\n'], output,
 
115
                    path_encoding='iso-8859-1')
 
116
        lines = output.getvalue().splitlines(True)
 
117
        self.check_patch(lines)
 
118
        self.assertEquals(['--- old_\xb5\t\n',
 
119
                           '+++ new_\xe5\t\n',
 
120
                           '@@ -1,1 +1,1 @@\n',
 
121
                           '-old_text\n',
 
122
                           '+new_text\n',
 
123
                           '\n',
 
124
                          ]
 
125
                          , lines)
 
126
 
 
127
    def test_internal_diff_returns_bytes(self):
 
128
        import StringIO
 
129
        output = StringIO.StringIO()
 
130
        internal_diff(u'old_\xb5', ['old_text\n'],
 
131
                    u'new_\xe5', ['new_text\n'], output)
 
132
        self.failUnless(isinstance(output.getvalue(), str),
 
133
            'internal_diff should return bytestrings')
 
134
 
79
135
 
80
136
class TestPatienceDiffLib(TestCase):
81
137