127
127
# make sure it supports passing in lists
131
, 'how are you today?\n'],
133
, 'how are you today?\n'],
131
'how are you today?\n'],
133
'how are you today?\n'],
134
134
[(0, 0, 1), (2, 1, 1)])
136
136
chk_blocks('aBccDe', 'abccde', [(0,0,1), (2,2,2), (5,5,1)])
150
150
chk_ops('', '', [])
151
151
chk_ops([], [], [])
152
152
chk_ops('abcd', 'abcd', [('equal', 0,4, 0,4)])
153
chk_ops('abcd', 'abce', [ ('equal', 0,3, 0,3)
154
, ('replace', 3,4, 3,4)
156
chk_ops('eabc', 'abce', [ ('delete', 0,1, 0,0)
157
, ('equal', 1,4, 0,3)
158
, ('insert', 4,4, 3,4)
160
chk_ops('eabce', 'abce', [ ('delete', 0,1, 0,0)
161
, ('equal', 1,5, 0,4)
153
chk_ops('abcd', 'abce', [('equal', 0,3, 0,3),
154
('replace', 3,4, 3,4)
156
chk_ops('eabc', 'abce', [('delete', 0,1, 0,0),
160
chk_ops('eabce', 'abce', [('delete', 0,1, 0,0),
163
chk_ops('abcde', 'abXde', [ ('equal', 0,2, 0,2)
164
, ('replace', 2,3, 2,3)
165
, ('equal', 3,5, 3,5)
163
chk_ops('abcde', 'abXde', [('equal', 0,2, 0,2),
164
('replace', 2,3, 2,3),
167
chk_ops('abcde', 'abXYZde', [ ('equal', 0,2, 0,2)
168
, ('replace', 2,3, 2,5)
169
, ('equal', 3,5, 5,7)
167
chk_ops('abcde', 'abXYZde', [('equal', 0,2, 0,2),
168
('replace', 2,3, 2,5),
171
chk_ops('abde', 'abXYZde', [ ('equal', 0,2, 0,2)
172
, ('insert', 2,2, 2,5)
173
, ('equal', 2,4, 5,7)
171
chk_ops('abde', 'abXYZde', [('equal', 0,2, 0,2),
172
('insert', 2,2, 2,5),
175
175
chk_ops('abcdefghijklmnop', 'abcdefxydefghijklmnop',
176
[ ('equal', 0,6, 0,6)
177
, ('insert', 6,6, 6,11)
178
, ('equal', 6,16, 11,21)
176
[('equal', 0,6, 0,6),
177
('insert', 6,6, 6,11),
178
('equal', 6,16, 11,21)
181
181
[ 'hello there\n'
183
183
, 'how are you today?\n'],
184
184
[ 'hello there\n'
185
185
, 'how are you today?\n'],
186
[ ('equal', 0,1, 0,1)
187
, ('delete', 1,2, 1,1)
188
, ('equal', 2,3, 1,2)
186
[('equal', 0,1, 0,1),
187
('delete', 1,2, 1,1),
190
190
chk_ops('aBccDe', 'abccde',
191
[ ('equal', 0,1, 0,1)
192
, ('replace', 1,2, 1,2)
193
, ('equal', 2,4, 2,4)
194
, ('replace', 4,5, 4,5)
195
, ('equal', 5,6, 5,6)
191
[('equal', 0,1, 0,1),
192
('replace', 1,2, 1,2),
194
('replace', 4,5, 4,5),
197
197
chk_ops('aBcdEcdFg', 'abcdecdfg',
198
[ ('equal', 0,1, 0,1)
199
, ('replace', 1,2, 1,2)
200
, ('equal', 2,4, 2,4)
201
, ('replace', 4,5, 4,5)
202
, ('equal', 5,7, 5,7)
203
, ('replace', 7,8, 7,8)
204
, ('equal', 8,9, 8,9)
198
[('equal', 0,1, 0,1),
199
('replace', 1,2, 1,2),
201
('replace', 4,5, 4,5),
203
('replace', 7,8, 7,8),
207
207
def test_multiple_ranges(self):
272
272
, [(0,0,1), (1, 4, 2), (9, 19, 1), (12, 23, 3)])
274
274
def test_cdv_unified_diff(self):
275
txt_a = [ 'hello there\n'
277
, 'how are you today?\n']
278
txt_b = [ 'hello there\n'
279
, 'how are you today?\n']
280
self.assertEquals([ '--- \n'
282
, '@@ -1,3 +1,2 @@\n'
285
, ' how are you today?\n'
275
txt_a = ['hello there\n',
277
'how are you today?\n']
278
txt_b = ['hello there\n',
279
'how are you today?\n']
280
self.assertEquals([ '--- \n',
285
' how are you today?\n'
287
287
, list(unified_diff(txt_a, txt_b
288
288
, sequencematcher=SequenceMatcher)))
289
289
txt_a = map(lambda x: x+'\n', 'abcdefghijklmnop')
290
290
txt_b = map(lambda x: x+'\n', 'abcdefxydefghijklmnop')
291
291
# This is the result with LongestCommonSubstring matching
292
self.assertEquals([ '--- \n'
294
, '@@ -1,6 +1,11 @@\n'
292
self.assertEquals(['--- \n',
294
'@@ -1,6 +1,11 @@\n',
306
306
, list(unified_diff(txt_a, txt_b)))
307
307
# And the cdv diff
308
self.assertEquals([ '--- \n'
310
, '@@ -4,6 +4,11 @@\n'
308
self.assertEquals(['--- \n',
310
'@@ -4,6 +4,11 @@\n',
323
323
, list(unified_diff(txt_a, txt_b,
324
324
sequencematcher=SequenceMatcher)))
327
327
class TestCDVDiffLibFiles(TestCaseInTempDir):
329
329
def test_cdv_unified_diff_files(self):
330
txt_a = [ 'hello there\n'
332
, 'how are you today?\n']
333
txt_b = [ 'hello there\n'
334
, 'how are you today?\n']
330
txt_a = ['hello there\n',
332
'how are you today?\n']
333
txt_b = ['hello there\n',
334
'how are you today?\n']
335
335
open('a1', 'wb').writelines(txt_a)
336
336
open('b1', 'wb').writelines(txt_b)
338
self.assertEquals([ '--- a1 \n'
340
, '@@ -1,3 +1,2 @@\n'
343
, ' how are you today?\n'
338
self.assertEquals(['--- a1 \n',
343
' how are you today?\n',
345
345
, list(unified_diff_files('a1', 'b1',
346
346
sequencematcher=SequenceMatcher)))
351
351
open('b2', 'wb').writelines(txt_b)
353
353
# This is the result with LongestCommonSubstring matching
354
self.assertEquals([ '--- a2 \n'
356
, '@@ -1,6 +1,11 @@\n'
354
self.assertEquals(['--- a2 \n',
356
'@@ -1,6 +1,11 @@\n',
368
368
, list(unified_diff_files('a2', 'b2')))
370
370
# And the cdv diff
371
self.assertEquals([ '--- a2 \n'
373
, '@@ -4,6 +4,11 @@\n'
371
self.assertEquals(['--- a2 \n',
373
'@@ -4,6 +4,11 @@\n',
386
386
, list(unified_diff_files('a2', 'b2',
387
387
sequencematcher=SequenceMatcher)))