Show More
@@ -1,73 +1,80 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("***", repr(a), repr(b)) |
|
14 | print("bad diff+patch result from\n %r to\n %r:" % (a, b)) | |
15 |
print("b |
|
15 | print("bdiff: %r" % d) | |
16 |
print( |
|
16 | print("patched: %r" % c[:200]) | |
17 | print(repr(d)) |
|
|||
18 |
|
17 | |||
19 | def test(a, b): |
|
18 | def test(a, b): | |
20 |
print(" |
|
19 | print("test", repr(a), repr(b)) | |
21 | test1(a, b) |
|
20 | test1(a, b) | |
22 | test1(b, a) |
|
21 | test1(b, a) | |
23 |
|
22 | |||
24 | 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") | |
25 | test("a\nb\nc\n", "a\nc\n") |
|
24 | test("a\nb\nc\n", "a\nc\n") | |
26 | test("", "") |
|
25 | test("", "") | |
27 | test("a\nb\nc", "a\nb\nc") |
|
26 | test("a\nb\nc", "a\nb\nc") | |
28 | test("a\nb\nc\nd\n", "a\nd\n") |
|
27 | test("a\nb\nc\nd\n", "a\nd\n") | |
29 | test("a\nb\nc\nd\n", "a\nc\ne\n") |
|
28 | test("a\nb\nc\nd\n", "a\nc\ne\n") | |
30 | test("a\nb\nc\n", "a\nc\n") |
|
29 | test("a\nb\nc\n", "a\nc\n") | |
31 | test("a\n", "c\na\nb\n") |
|
30 | test("a\n", "c\na\nb\n") | |
32 | test("a\n", "") |
|
31 | test("a\n", "") | |
33 | test("a\n", "b\nc\n") |
|
32 | test("a\n", "b\nc\n") | |
34 | test("a\n", "c\na\n") |
|
33 | test("a\n", "c\na\n") | |
35 | test("", "adjfkjdjksdhfksj") |
|
34 | test("", "adjfkjdjksdhfksj") | |
36 | test("", "ab") |
|
35 | test("", "ab") | |
37 | test("", "abc") |
|
36 | test("", "abc") | |
38 | test("a", "a") |
|
37 | test("a", "a") | |
39 | test("ab", "ab") |
|
38 | test("ab", "ab") | |
40 | test("abc", "abc") |
|
39 | test("abc", "abc") | |
41 | test("a\n", "a\n") |
|
40 | test("a\n", "a\n") | |
42 | test("a\nb", "a\nb") |
|
41 | test("a\nb", "a\nb") | |
43 |
|
42 | |||
44 | #issue1295 |
|
43 | #issue1295 | |
45 | def showdiff(a, b): |
|
44 | def showdiff(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 | while pos < len(bin): |
|
49 | while pos < len(bin): | |
49 | p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12]) |
|
50 | p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12]) | |
50 | pos += 12 |
|
51 | pos += 12 | |
51 | print(p1, p2, repr(bin[pos:pos + l])) |
|
52 | if p1: | |
|
53 | print('', repr(a[q:p1])) | |||
|
54 | print('', p1, p2, repr(a[p1:p2]), '->', repr(bin[pos:pos + l])) | |||
52 | pos += l |
|
55 | pos += l | |
|
56 | q = p2 | |||
|
57 | if q < len(a): | |||
|
58 | print('', repr(a[q:])) | |||
|
59 | ||||
53 | 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") | |
54 | 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") | |
55 | # 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 | |
56 | 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", | |
57 | "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") | |
58 |
|
65 | |||
59 | print("done") |
|
66 | print("done") | |
60 |
|
67 | |||
61 | def testfixws(a, b, allws): |
|
68 | def testfixws(a, b, allws): | |
62 | c = bdiff.fixws(a, allws) |
|
69 | c = bdiff.fixws(a, allws) | |
63 | if c != b: |
|
70 | if c != b: | |
64 | print("*** fixws", repr(a), repr(b), allws) |
|
71 | print("*** fixws", repr(a), repr(b), allws) | |
65 | print("got:") |
|
72 | print("got:") | |
66 | print(repr(c)) |
|
73 | print(repr(c)) | |
67 |
|
74 | |||
68 | testfixws(" \ta\r b\t\n", "ab\n", 1) |
|
75 | testfixws(" \ta\r b\t\n", "ab\n", 1) | |
69 | testfixws(" \ta\r b\t\n", " a b\n", 0) |
|
76 | testfixws(" \ta\r b\t\n", " a b\n", 0) | |
70 | testfixws("", "", 1) |
|
77 | testfixws("", "", 1) | |
71 | testfixws("", "", 0) |
|
78 | testfixws("", "", 0) | |
72 |
|
79 | |||
73 | print("done") |
|
80 | print("done") |
@@ -1,27 +1,44 b'' | |||||
1 |
|
|
1 | test 'a\nc\n\n\n\n' 'a\nb\n\n\n' | |
2 |
|
|
2 | test 'a\nb\nc\n' 'a\nc\n' | |
3 |
|
|
3 | test '' '' | |
4 |
|
|
4 | test 'a\nb\nc' 'a\nb\nc' | |
5 |
|
|
5 | test 'a\nb\nc\nd\n' 'a\nd\n' | |
6 |
|
|
6 | test 'a\nb\nc\nd\n' 'a\nc\ne\n' | |
7 |
|
|
7 | test 'a\nb\nc\n' 'a\nc\n' | |
8 |
|
|
8 | test 'a\n' 'c\na\nb\n' | |
9 |
|
|
9 | test 'a\n' '' | |
10 |
|
|
10 | test 'a\n' 'b\nc\n' | |
11 |
|
|
11 | test 'a\n' 'c\na\n' | |
12 |
|
|
12 | test '' 'adjfkjdjksdhfksj' | |
13 |
|
|
13 | test '' 'ab' | |
14 |
|
|
14 | test '' 'abc' | |
15 |
|
|
15 | test 'a' 'a' | |
16 |
|
|
16 | test 'ab' 'ab' | |
17 |
|
|
17 | test 'abc' 'abc' | |
18 |
|
|
18 | test 'a\n' 'a\n' | |
19 |
|
|
19 | test 'a\nb' 'a\nb' | |
20 | 6 6 'y\n\n' |
|
20 | showdiff( | |
21 | 6 6 'y\n\n' |
|
21 | 'x\n\nx\n\nx\n\nx\n\nz\n', | |
22 | 9 9 'y\n\n' |
|
22 | 'x\n\nx\n\ny\n\nx\n\nx\n\nz\n'): | |
23 |
|
|
23 | 'x\n\nx\n\n' | |
24 | 12 12 'b\nc\n.\n' |
|
24 | 6 6 '' -> 'y\n\n' | |
25 | 16 18 '' |
|
25 | 'x\n\nx\n\nz\n' | |
|
26 | showdiff( | |||
|
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'): | |||
|
29 | 'x\n\nx\n\n' | |||
|
30 | 6 6 '' -> 'y\n\n' | |||
|
31 | 'x\n\n' | |||
|
32 | 9 9 '' -> 'y\n\n' | |||
|
33 | 'x\n\nz\n' | |||
|
34 | showdiff( | |||
|
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'): | |||
|
37 | 0 0 '' -> 'a\nb\nb\n' | |||
|
38 | 'a\nb\nb\nb\nc\n.\n' | |||
|
39 | 12 12 '' -> 'b\nc\n.\n' | |||
|
40 | 'd\ne\n' | |||
|
41 | 16 18 '.\n' -> '' | |||
|
42 | 'f\n' | |||
26 | done |
|
43 | done | |
27 | done |
|
44 | done |
General Comments 0
You need to be logged in to leave comments.
Login now