Show More
@@ -1,44 +1,53 b'' | |||||
1 | from __future__ import absolute_import, print_function |
|
1 | from __future__ import absolute_import, print_function | |
2 | import struct |
|
2 | import struct | |
|
3 | import unittest | |||
|
4 | ||||
|
5 | import silenttestrunner | |||
|
6 | ||||
3 | from mercurial import ( |
|
7 | from mercurial import ( | |
4 | bdiff, |
|
8 | bdiff, | |
5 | mpatch, |
|
9 | mpatch, | |
6 | ) |
|
10 | ) | |
7 |
|
11 | |||
8 | def test1(a, b): |
|
12 | class BdiffTests(unittest.TestCase): | |
9 | d = bdiff.bdiff(a, b) |
|
|||
10 | c = a |
|
|||
11 | if d: |
|
|||
12 | c = mpatch.patches(a, [d]) |
|
|||
13 | if c != b: |
|
|||
14 | print("bad diff+patch result from\n %r to\n %r:" % (a, b)) |
|
|||
15 | print("bdiff: %r" % d) |
|
|||
16 | print("patched: %r" % c[:200]) |
|
|||
17 |
|
13 | |||
18 | def test(a, b): |
|
14 | def assert_bdiff_applies(self, a, b): | |
19 | print("test", repr(a), repr(b)) |
|
15 | d = bdiff.bdiff(a, b) | |
20 | test1(a, b) |
|
16 | c = a | |
21 | test1(b, a) |
|
17 | if d: | |
|
18 | c = mpatch.patches(a, [d]) | |||
|
19 | self.assertEqual( | |||
|
20 | c, b, ("bad diff+patch result from\n %r to\n " | |||
|
21 | "%r: \nbdiff: %r\npatched: %r" % (a, b, d, c[:200]))) | |||
|
22 | ||||
|
23 | def assert_bdiff(self, a, b): | |||
|
24 | self.assert_bdiff_applies(a, b) | |||
|
25 | self.assert_bdiff_applies(b, a) | |||
22 |
|
26 | |||
23 | test("a\nc\n\n\n\n", "a\nb\n\n\n") |
|
27 | def test_bdiff_basic(self): | |
24 | test("a\nb\nc\n", "a\nc\n") |
|
28 | cases = [ | |
25 | test("", "") |
|
29 | ("a\nc\n\n\n\n", "a\nb\n\n\n"), | |
26 |
|
|
30 | ("a\nb\nc\n", "a\nc\n"), | |
27 | test("a\nb\nc\nd\n", "a\nd\n") |
|
31 | ("", ""), | |
28 | test("a\nb\nc\nd\n", "a\nc\ne\n") |
|
32 | ("a\nb\nc", "a\nb\nc"), | |
29 |
|
|
33 | ("a\nb\nc\nd\n", "a\nd\n"), | |
30 | test("a\n", "c\na\nb\n") |
|
34 | ("a\nb\nc\nd\n", "a\nc\ne\n"), | |
31 | test("a\n", "") |
|
35 | ("a\nb\nc\n", "a\nc\n"), | |
32 | test("a\n", "b\nc\n") |
|
36 | ("a\n", "c\na\nb\n"), | |
33 | test("a\n", "c\na\n") |
|
37 | ("a\n", ""), | |
34 | test("", "adjfkjdjksdhfksj") |
|
38 | ("a\n", "b\nc\n"), | |
35 | test("", "ab") |
|
39 | ("a\n", "c\na\n"), | |
36 | test("", "abc") |
|
40 | ("", "adjfkjdjksdhfksj"), | |
37 | test("a", "a") |
|
41 | ("", "ab"), | |
38 | test("ab", "ab") |
|
42 | ("", "abc"), | |
39 | test("abc", "abc") |
|
43 | ("a", "a"), | |
40 | test("a\n", "a\n") |
|
44 | ("ab", "ab"), | |
41 | test("a\nb", "a\nb") |
|
45 | ("abc", "abc"), | |
|
46 | ("a\n", "a\n"), | |||
|
47 | ("a\nb", "a\nb"), | |||
|
48 | ] | |||
|
49 | for a, b in cases: | |||
|
50 | self.assert_bdiff(a, b) | |||
42 |
|
51 | |||
43 | #issue1295 |
|
52 | #issue1295 | |
44 | def showdiff(a, b): |
|
53 | def showdiff(a, b): | |
@@ -92,3 +101,6 b' print("Diff 3 to 1 lines - preference fo' | |||||
92 | showdiff('a\n' * 3, 'a\n') |
|
101 | showdiff('a\n' * 3, 'a\n') | |
93 | print("Diff 5 to 1 lines - preference for removing trailing lines:") |
|
102 | print("Diff 5 to 1 lines - preference for removing trailing lines:") | |
94 | showdiff('a\n' * 5, 'a\n') |
|
103 | showdiff('a\n' * 5, 'a\n') | |
|
104 | ||||
|
105 | if __name__ == '__main__': | |||
|
106 | silenttestrunner.main(__name__) |
@@ -1,22 +1,3 b'' | |||||
1 | test 'a\nc\n\n\n\n' 'a\nb\n\n\n' |
|
|||
2 | test 'a\nb\nc\n' 'a\nc\n' |
|
|||
3 | test '' '' |
|
|||
4 | test 'a\nb\nc' 'a\nb\nc' |
|
|||
5 | test 'a\nb\nc\nd\n' 'a\nd\n' |
|
|||
6 | test 'a\nb\nc\nd\n' 'a\nc\ne\n' |
|
|||
7 | test 'a\nb\nc\n' 'a\nc\n' |
|
|||
8 | test 'a\n' 'c\na\nb\n' |
|
|||
9 | test 'a\n' '' |
|
|||
10 | test 'a\n' 'b\nc\n' |
|
|||
11 | test 'a\n' 'c\na\n' |
|
|||
12 | test '' 'adjfkjdjksdhfksj' |
|
|||
13 | test '' 'ab' |
|
|||
14 | test '' 'abc' |
|
|||
15 | test 'a' 'a' |
|
|||
16 | test 'ab' 'ab' |
|
|||
17 | test 'abc' 'abc' |
|
|||
18 | test 'a\n' 'a\n' |
|
|||
19 | test 'a\nb' 'a\nb' |
|
|||
20 | showdiff( |
|
1 | showdiff( | |
21 | 'x\n\nx\n\nx\n\nx\n\nz\n', |
|
2 | 'x\n\nx\n\nx\n\nx\n\nz\n', | |
22 | 'x\n\nx\n\ny\n\nx\n\nx\n\nz\n'): |
|
3 | 'x\n\nx\n\ny\n\nx\n\nx\n\nz\n'): |
General Comments 0
You need to be logged in to leave comments.
Login now