Show More
@@ -1,4 +1,5 b'' | |||
|
1 | 1 | from __future__ import absolute_import, print_function |
|
2 | import collections | |
|
2 | 3 | import struct |
|
3 | 4 | import unittest |
|
4 | 5 | |
@@ -9,6 +10,11 b' from mercurial import (' | |||
|
9 | 10 | mpatch, |
|
10 | 11 | ) |
|
11 | 12 | |
|
13 | class diffreplace( | |
|
14 | collections.namedtuple('diffreplace', 'start end from_ to')): | |
|
15 | def __repr__(self): | |
|
16 | return 'diffreplace(%r, %r, %r, %r)' % self | |
|
17 | ||
|
12 | 18 | class BdiffTests(unittest.TestCase): |
|
13 | 19 | |
|
14 | 20 | def assert_bdiff_applies(self, a, b): |
@@ -49,7 +55,45 b' class BdiffTests(unittest.TestCase):' | |||
|
49 | 55 | for a, b in cases: |
|
50 | 56 | self.assert_bdiff(a, b) |
|
51 | 57 | |
|
52 | #issue1295 | |
|
58 | def showdiff(self, a, b): | |
|
59 | bin = bdiff.bdiff(a, b) | |
|
60 | pos = 0 | |
|
61 | q = 0 | |
|
62 | actions = [] | |
|
63 | while pos < len(bin): | |
|
64 | p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12]) | |
|
65 | pos += 12 | |
|
66 | if p1: | |
|
67 | actions.append(a[q:p1]) | |
|
68 | actions.append(diffreplace(p1, p2, a[p1:p2], bin[pos:pos + l])) | |
|
69 | pos += l | |
|
70 | q = p2 | |
|
71 | if q < len(a): | |
|
72 | actions.append(a[q:]) | |
|
73 | return actions | |
|
74 | ||
|
75 | def test_issue1295(self): | |
|
76 | cases = [ | |
|
77 | ("x\n\nx\n\nx\n\nx\n\nz\n", "x\n\nx\n\ny\n\nx\n\nx\n\nz\n", | |
|
78 | ['x\n\nx\n\n', diffreplace(6, 6, '', 'y\n\n'), 'x\n\nx\n\nz\n']), | |
|
79 | ("x\n\nx\n\nx\n\nx\n\nz\n", "x\n\nx\n\ny\n\nx\n\ny\n\nx\n\nz\n", | |
|
80 | ['x\n\nx\n\n', | |
|
81 | diffreplace(6, 6, '', 'y\n\n'), | |
|
82 | 'x\n\n', | |
|
83 | diffreplace(9, 9, '', 'y\n\n'), | |
|
84 | 'x\n\nz\n']), | |
|
85 | # we should pick up abbbc. rather than bc.de as the longest match | |
|
86 | ("a\nb\nb\nb\nc\n.\nd\ne\n.\nf\n", | |
|
87 | "a\nb\nb\na\nb\nb\nb\nc\n.\nb\nc\n.\nd\ne\nf\n", | |
|
88 | ['a\nb\nb\n', | |
|
89 | diffreplace(6, 6, '', 'a\nb\nb\nb\nc\n.\n'), | |
|
90 | 'b\nc\n.\nd\ne\n', | |
|
91 | diffreplace(16, 18, '.\n', ''), | |
|
92 | 'f\n']), | |
|
93 | ] | |
|
94 | for old, new, want in cases: | |
|
95 | self.assertEqual(self.showdiff(old, new), want) | |
|
96 | ||
|
53 | 97 | def showdiff(a, b): |
|
54 | 98 | print('showdiff(\n %r,\n %r):' % (a, b)) |
|
55 | 99 | bin = bdiff.bdiff(a, b) |
@@ -66,14 +110,6 b' def showdiff(a, b):' | |||
|
66 | 110 | if q < len(a): |
|
67 | 111 | print('', repr(a[q:])) |
|
68 | 112 | |
|
69 | showdiff("x\n\nx\n\nx\n\nx\n\nz\n", "x\n\nx\n\ny\n\nx\n\nx\n\nz\n") | |
|
70 | showdiff("x\n\nx\n\nx\n\nx\n\nz\n", "x\n\nx\n\ny\n\nx\n\ny\n\nx\n\nz\n") | |
|
71 | # we should pick up abbbc. rather than bc.de as the longest match | |
|
72 | showdiff("a\nb\nb\nb\nc\n.\nd\ne\n.\nf\n", | |
|
73 | "a\nb\nb\na\nb\nb\nb\nc\n.\nb\nc\n.\nd\ne\nf\n") | |
|
74 | ||
|
75 | print("done") | |
|
76 | ||
|
77 | 113 | def testfixws(a, b, allws): |
|
78 | 114 | c = bdiff.fixws(a, allws) |
|
79 | 115 | if c != b: |
@@ -1,26 +1,3 b'' | |||
|
1 | showdiff( | |
|
2 | 'x\n\nx\n\nx\n\nx\n\nz\n', | |
|
3 | 'x\n\nx\n\ny\n\nx\n\nx\n\nz\n'): | |
|
4 | 'x\n\nx\n\n' | |
|
5 | 6 6 '' -> 'y\n\n' | |
|
6 | 'x\n\nx\n\nz\n' | |
|
7 | showdiff( | |
|
8 | 'x\n\nx\n\nx\n\nx\n\nz\n', | |
|
9 | 'x\n\nx\n\ny\n\nx\n\ny\n\nx\n\nz\n'): | |
|
10 | 'x\n\nx\n\n' | |
|
11 | 6 6 '' -> 'y\n\n' | |
|
12 | 'x\n\n' | |
|
13 | 9 9 '' -> 'y\n\n' | |
|
14 | 'x\n\nz\n' | |
|
15 | showdiff( | |
|
16 | 'a\nb\nb\nb\nc\n.\nd\ne\n.\nf\n', | |
|
17 | 'a\nb\nb\na\nb\nb\nb\nc\n.\nb\nc\n.\nd\ne\nf\n'): | |
|
18 | 'a\nb\nb\n' | |
|
19 | 6 6 '' -> 'a\nb\nb\nb\nc\n.\n' | |
|
20 | 'b\nc\n.\nd\ne\n' | |
|
21 | 16 18 '.\n' -> '' | |
|
22 | 'f\n' | |
|
23 | done | |
|
24 | 1 | done |
|
25 | 2 | Nice diff for a trivial change: |
|
26 | 3 | showdiff( |
General Comments 0
You need to be logged in to leave comments.
Login now