Show More
@@ -1,80 +1,94 b'' | |||||
1 | from __future__ import absolute_import, print_function |
|
1 | from __future__ import absolute_import, print_function | |
2 | import struct |
|
2 | import struct | |
3 | from mercurial import ( |
|
3 | from mercurial import ( | |
4 | bdiff, |
|
4 | bdiff, | |
5 | mpatch, |
|
5 | mpatch, | |
6 | ) |
|
6 | ) | |
7 |
|
7 | |||
8 | def test1(a, b): |
|
8 | def test1(a, b): | |
9 | d = bdiff.bdiff(a, b) |
|
9 | d = bdiff.bdiff(a, b) | |
10 | c = a |
|
10 | c = a | |
11 | if d: |
|
11 | if d: | |
12 | c = mpatch.patches(a, [d]) |
|
12 | c = mpatch.patches(a, [d]) | |
13 | if c != b: |
|
13 | if c != b: | |
14 | print("bad diff+patch result from\n %r to\n %r:" % (a, b)) |
|
14 | print("bad diff+patch result from\n %r to\n %r:" % (a, b)) | |
15 | print("bdiff: %r" % d) |
|
15 | print("bdiff: %r" % d) | |
16 | print("patched: %r" % c[:200]) |
|
16 | print("patched: %r" % c[:200]) | |
17 |
|
17 | |||
18 | def test(a, b): |
|
18 | def test(a, b): | |
19 | print("test", repr(a), repr(b)) |
|
19 | print("test", repr(a), repr(b)) | |
20 | test1(a, b) |
|
20 | test1(a, b) | |
21 | test1(b, a) |
|
21 | test1(b, a) | |
22 |
|
22 | |||
23 | test("a\nc\n\n\n\n", "a\nb\n\n\n") |
|
23 | test("a\nc\n\n\n\n", "a\nb\n\n\n") | |
24 | test("a\nb\nc\n", "a\nc\n") |
|
24 | test("a\nb\nc\n", "a\nc\n") | |
25 | test("", "") |
|
25 | test("", "") | |
26 | test("a\nb\nc", "a\nb\nc") |
|
26 | test("a\nb\nc", "a\nb\nc") | |
27 | test("a\nb\nc\nd\n", "a\nd\n") |
|
27 | test("a\nb\nc\nd\n", "a\nd\n") | |
28 | test("a\nb\nc\nd\n", "a\nc\ne\n") |
|
28 | test("a\nb\nc\nd\n", "a\nc\ne\n") | |
29 | test("a\nb\nc\n", "a\nc\n") |
|
29 | test("a\nb\nc\n", "a\nc\n") | |
30 | test("a\n", "c\na\nb\n") |
|
30 | test("a\n", "c\na\nb\n") | |
31 | test("a\n", "") |
|
31 | test("a\n", "") | |
32 | test("a\n", "b\nc\n") |
|
32 | test("a\n", "b\nc\n") | |
33 | test("a\n", "c\na\n") |
|
33 | test("a\n", "c\na\n") | |
34 | test("", "adjfkjdjksdhfksj") |
|
34 | test("", "adjfkjdjksdhfksj") | |
35 | test("", "ab") |
|
35 | test("", "ab") | |
36 | test("", "abc") |
|
36 | test("", "abc") | |
37 | test("a", "a") |
|
37 | test("a", "a") | |
38 | test("ab", "ab") |
|
38 | test("ab", "ab") | |
39 | test("abc", "abc") |
|
39 | test("abc", "abc") | |
40 | test("a\n", "a\n") |
|
40 | test("a\n", "a\n") | |
41 | test("a\nb", "a\nb") |
|
41 | test("a\nb", "a\nb") | |
42 |
|
42 | |||
43 | #issue1295 |
|
43 | #issue1295 | |
44 | def showdiff(a, b): |
|
44 | def showdiff(a, b): | |
45 | print('showdiff(\n %r,\n %r):' % (a, b)) |
|
45 | print('showdiff(\n %r,\n %r):' % (a, b)) | |
46 | bin = bdiff.bdiff(a, b) |
|
46 | bin = bdiff.bdiff(a, b) | |
47 | pos = 0 |
|
47 | pos = 0 | |
48 | q = 0 |
|
48 | q = 0 | |
49 | while pos < len(bin): |
|
49 | while pos < len(bin): | |
50 | p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12]) |
|
50 | p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12]) | |
51 | pos += 12 |
|
51 | pos += 12 | |
52 | if p1: |
|
52 | if p1: | |
53 | print('', repr(a[q:p1])) |
|
53 | print('', repr(a[q:p1])) | |
54 | print('', p1, p2, repr(a[p1:p2]), '->', repr(bin[pos:pos + l])) |
|
54 | print('', p1, p2, repr(a[p1:p2]), '->', repr(bin[pos:pos + l])) | |
55 | pos += l |
|
55 | pos += l | |
56 | q = p2 |
|
56 | q = p2 | |
57 | if q < len(a): |
|
57 | if q < len(a): | |
58 | print('', repr(a[q:])) |
|
58 | print('', repr(a[q:])) | |
59 |
|
59 | |||
60 | showdiff("x\n\nx\n\nx\n\nx\n\nz\n", "x\n\nx\n\ny\n\nx\n\nx\n\nz\n") |
|
60 | showdiff("x\n\nx\n\nx\n\nx\n\nz\n", "x\n\nx\n\ny\n\nx\n\nx\n\nz\n") | |
61 | 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") |
|
61 | 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") | |
62 | # we should pick up abbbc. rather than bc.de as the longest match |
|
62 | # we should pick up abbbc. rather than bc.de as the longest match | |
63 | showdiff("a\nb\nb\nb\nc\n.\nd\ne\n.\nf\n", |
|
63 | showdiff("a\nb\nb\nb\nc\n.\nd\ne\n.\nf\n", | |
64 | "a\nb\nb\na\nb\nb\nb\nc\n.\nb\nc\n.\nd\ne\nf\n") |
|
64 | "a\nb\nb\na\nb\nb\nb\nc\n.\nb\nc\n.\nd\ne\nf\n") | |
65 |
|
65 | |||
66 | print("done") |
|
66 | print("done") | |
67 |
|
67 | |||
68 | def testfixws(a, b, allws): |
|
68 | def testfixws(a, b, allws): | |
69 | c = bdiff.fixws(a, allws) |
|
69 | c = bdiff.fixws(a, allws) | |
70 | if c != b: |
|
70 | if c != b: | |
71 | print("*** fixws", repr(a), repr(b), allws) |
|
71 | print("*** fixws", repr(a), repr(b), allws) | |
72 | print("got:") |
|
72 | print("got:") | |
73 | print(repr(c)) |
|
73 | print(repr(c)) | |
74 |
|
74 | |||
75 | testfixws(" \ta\r b\t\n", "ab\n", 1) |
|
75 | testfixws(" \ta\r b\t\n", "ab\n", 1) | |
76 | testfixws(" \ta\r b\t\n", " a b\n", 0) |
|
76 | testfixws(" \ta\r b\t\n", " a b\n", 0) | |
77 | testfixws("", "", 1) |
|
77 | testfixws("", "", 1) | |
78 | testfixws("", "", 0) |
|
78 | testfixws("", "", 0) | |
79 |
|
79 | |||
80 | print("done") |
|
80 | print("done") | |
|
81 | ||||
|
82 | print("Odd diff for a trivial change:") | |||
|
83 | showdiff( | |||
|
84 | ''.join('<%s\n-\n' % i for i in range(5)), | |||
|
85 | ''.join('>%s\n-\n' % i for i in range(5))) | |||
|
86 | ||||
|
87 | print("Diff 1 to 3 lines - preference for adding / removing at the end of sequences:") | |||
|
88 | showdiff('a\n', 'a\n' * 3) | |||
|
89 | print("Diff 1 to 5 lines - preference for adding / removing at the end of sequences:") | |||
|
90 | showdiff('a\n', 'a\n' * 5) | |||
|
91 | print("Diff 3 to 1 lines - preference for adding / removing at the end of sequences:") | |||
|
92 | showdiff('a\n' * 3, 'a\n') | |||
|
93 | print("Diff 5 to 1 lines - this diff seems weird:") | |||
|
94 | showdiff('a\n' * 5, 'a\n') |
@@ -1,44 +1,82 b'' | |||||
1 | test 'a\nc\n\n\n\n' 'a\nb\n\n\n' |
|
1 | test 'a\nc\n\n\n\n' 'a\nb\n\n\n' | |
2 | test 'a\nb\nc\n' 'a\nc\n' |
|
2 | test 'a\nb\nc\n' 'a\nc\n' | |
3 | test '' '' |
|
3 | test '' '' | |
4 | test 'a\nb\nc' 'a\nb\nc' |
|
4 | test 'a\nb\nc' 'a\nb\nc' | |
5 | test 'a\nb\nc\nd\n' 'a\nd\n' |
|
5 | test 'a\nb\nc\nd\n' 'a\nd\n' | |
6 | test 'a\nb\nc\nd\n' 'a\nc\ne\n' |
|
6 | test 'a\nb\nc\nd\n' 'a\nc\ne\n' | |
7 | test 'a\nb\nc\n' 'a\nc\n' |
|
7 | test 'a\nb\nc\n' 'a\nc\n' | |
8 | test 'a\n' 'c\na\nb\n' |
|
8 | test 'a\n' 'c\na\nb\n' | |
9 | test 'a\n' '' |
|
9 | test 'a\n' '' | |
10 | test 'a\n' 'b\nc\n' |
|
10 | test 'a\n' 'b\nc\n' | |
11 | test 'a\n' 'c\na\n' |
|
11 | test 'a\n' 'c\na\n' | |
12 | test '' 'adjfkjdjksdhfksj' |
|
12 | test '' 'adjfkjdjksdhfksj' | |
13 | test '' 'ab' |
|
13 | test '' 'ab' | |
14 | test '' 'abc' |
|
14 | test '' 'abc' | |
15 | test 'a' 'a' |
|
15 | test 'a' 'a' | |
16 | test 'ab' 'ab' |
|
16 | test 'ab' 'ab' | |
17 | test 'abc' 'abc' |
|
17 | test 'abc' 'abc' | |
18 | test 'a\n' 'a\n' |
|
18 | test 'a\n' 'a\n' | |
19 | test 'a\nb' 'a\nb' |
|
19 | test 'a\nb' 'a\nb' | |
20 | showdiff( |
|
20 | showdiff( | |
21 | 'x\n\nx\n\nx\n\nx\n\nz\n', |
|
21 | 'x\n\nx\n\nx\n\nx\n\nz\n', | |
22 | 'x\n\nx\n\ny\n\nx\n\nx\n\nz\n'): |
|
22 | 'x\n\nx\n\ny\n\nx\n\nx\n\nz\n'): | |
23 | 'x\n\nx\n\n' |
|
23 | 'x\n\nx\n\n' | |
24 | 6 6 '' -> 'y\n\n' |
|
24 | 6 6 '' -> 'y\n\n' | |
25 | 'x\n\nx\n\nz\n' |
|
25 | 'x\n\nx\n\nz\n' | |
26 | showdiff( |
|
26 | showdiff( | |
27 | 'x\n\nx\n\nx\n\nx\n\nz\n', |
|
27 | 'x\n\nx\n\nx\n\nx\n\nz\n', | |
28 | 'x\n\nx\n\ny\n\nx\n\ny\n\nx\n\nz\n'): |
|
28 | 'x\n\nx\n\ny\n\nx\n\ny\n\nx\n\nz\n'): | |
29 | 'x\n\nx\n\n' |
|
29 | 'x\n\nx\n\n' | |
30 | 6 6 '' -> 'y\n\n' |
|
30 | 6 6 '' -> 'y\n\n' | |
31 | 'x\n\n' |
|
31 | 'x\n\n' | |
32 | 9 9 '' -> 'y\n\n' |
|
32 | 9 9 '' -> 'y\n\n' | |
33 | 'x\n\nz\n' |
|
33 | 'x\n\nz\n' | |
34 | showdiff( |
|
34 | showdiff( | |
35 | 'a\nb\nb\nb\nc\n.\nd\ne\n.\nf\n', |
|
35 | 'a\nb\nb\nb\nc\n.\nd\ne\n.\nf\n', | |
36 | 'a\nb\nb\na\nb\nb\nb\nc\n.\nb\nc\n.\nd\ne\nf\n'): |
|
36 | 'a\nb\nb\na\nb\nb\nb\nc\n.\nb\nc\n.\nd\ne\nf\n'): | |
37 | 0 0 '' -> 'a\nb\nb\n' |
|
37 | 0 0 '' -> 'a\nb\nb\n' | |
38 | 'a\nb\nb\nb\nc\n.\n' |
|
38 | 'a\nb\nb\nb\nc\n.\n' | |
39 | 12 12 '' -> 'b\nc\n.\n' |
|
39 | 12 12 '' -> 'b\nc\n.\n' | |
40 | 'd\ne\n' |
|
40 | 'd\ne\n' | |
41 | 16 18 '.\n' -> '' |
|
41 | 16 18 '.\n' -> '' | |
42 | 'f\n' |
|
42 | 'f\n' | |
43 | done |
|
43 | done | |
44 | done |
|
44 | done | |
|
45 | Odd diff for a trivial change: | |||
|
46 | showdiff( | |||
|
47 | '<0\n-\n<1\n-\n<2\n-\n<3\n-\n<4\n-\n', | |||
|
48 | '>0\n-\n>1\n-\n>2\n-\n>3\n-\n>4\n-\n'): | |||
|
49 | 0 8 '<0\n-\n<1\n' -> '>0\n' | |||
|
50 | '-\n' | |||
|
51 | 10 13 '<2\n' -> '>1\n' | |||
|
52 | '-\n' | |||
|
53 | 15 18 '<3\n' -> '>2\n' | |||
|
54 | '-\n' | |||
|
55 | 20 23 '<4\n' -> '>3\n' | |||
|
56 | '-\n' | |||
|
57 | 25 25 '' -> '>4\n-\n' | |||
|
58 | Diff 1 to 3 lines - preference for adding / removing at the end of sequences: | |||
|
59 | showdiff( | |||
|
60 | 'a\n', | |||
|
61 | 'a\na\na\n'): | |||
|
62 | 'a\n' | |||
|
63 | 2 2 '' -> 'a\na\n' | |||
|
64 | Diff 1 to 5 lines - preference for adding / removing at the end of sequences: | |||
|
65 | showdiff( | |||
|
66 | 'a\n', | |||
|
67 | 'a\na\na\na\na\n'): | |||
|
68 | 'a\n' | |||
|
69 | 2 2 '' -> 'a\na\na\na\n' | |||
|
70 | Diff 3 to 1 lines - preference for adding / removing at the end of sequences: | |||
|
71 | showdiff( | |||
|
72 | 'a\na\na\n', | |||
|
73 | 'a\n'): | |||
|
74 | 'a\n' | |||
|
75 | 2 6 'a\na\n' -> '' | |||
|
76 | Diff 5 to 1 lines - this diff seems weird: | |||
|
77 | showdiff( | |||
|
78 | 'a\na\na\na\na\n', | |||
|
79 | 'a\n'): | |||
|
80 | 0 2 'a\n' -> '' | |||
|
81 | 'a\n' | |||
|
82 | 4 10 'a\na\na\n' -> '' |
General Comments 0
You need to be logged in to leave comments.
Login now