24 p2data = b'a\nc\nd\n' |
30 p2data = b'a\nc\nd\n' |
25 childdata = b'a\nb2\nc\nc2\nd\n' |
31 childdata = b'a\nb2\nc\nc2\nd\n' |
26 diffopts = mdiff.diffopts() |
32 diffopts = mdiff.diffopts() |
27 |
33 |
28 def decorate(text, fctx): |
34 def decorate(text, fctx): |
29 return ([annotateline(fctx=fctx, lineno=i) |
35 n = text.count(b'\n') |
30 for i in range(1, text.count(b'\n') + 1)], |
36 linenos = pycompat.rangelist(1, n + 1) |
31 text) |
37 return _annotatedfile([fctx] * n, linenos, [False] * n, text) |
32 |
38 |
33 # Basic usage |
39 # Basic usage |
34 |
40 |
35 oldann = decorate(olddata, oldfctx) |
41 oldann = decorate(olddata, oldfctx) |
36 p1ann = decorate(p1data, p1fctx) |
42 p1ann = decorate(p1data, p1fctx) |
37 p1ann = _annotatepair([oldann], p1fctx, p1ann, False, diffopts) |
43 p1ann = _annotatepair([oldann], p1fctx, p1ann, False, diffopts) |
38 self.assertEqual(p1ann[0], [ |
44 self.assertEqual(tr(p1ann), [ |
39 annotateline(b'old', 1), |
45 annotateline(b'old', 1), |
40 annotateline(b'old', 2), |
46 annotateline(b'old', 2), |
41 annotateline(b'p1', 3), |
47 annotateline(b'p1', 3), |
42 ]) |
48 ]) |
43 |
49 |
44 p2ann = decorate(p2data, p2fctx) |
50 p2ann = decorate(p2data, p2fctx) |
45 p2ann = _annotatepair([oldann], p2fctx, p2ann, False, diffopts) |
51 p2ann = _annotatepair([oldann], p2fctx, p2ann, False, diffopts) |
46 self.assertEqual(p2ann[0], [ |
52 self.assertEqual(tr(p2ann), [ |
47 annotateline(b'old', 1), |
53 annotateline(b'old', 1), |
48 annotateline(b'p2', 2), |
54 annotateline(b'p2', 2), |
49 annotateline(b'p2', 3), |
55 annotateline(b'p2', 3), |
50 ]) |
56 ]) |
51 |
57 |
52 # Test with multiple parents (note the difference caused by ordering) |
58 # Test with multiple parents (note the difference caused by ordering) |
53 |
59 |
54 childann = decorate(childdata, childfctx) |
60 childann = decorate(childdata, childfctx) |
55 childann = _annotatepair([p1ann, p2ann], childfctx, childann, False, |
61 childann = _annotatepair([p1ann, p2ann], childfctx, childann, False, |
56 diffopts) |
62 diffopts) |
57 self.assertEqual(childann[0], [ |
63 self.assertEqual(tr(childann), [ |
58 annotateline(b'old', 1), |
64 annotateline(b'old', 1), |
59 annotateline(b'c', 2), |
65 annotateline(b'c', 2), |
60 annotateline(b'p2', 2), |
66 annotateline(b'p2', 2), |
61 annotateline(b'c', 4), |
67 annotateline(b'c', 4), |
62 annotateline(b'p2', 3), |
68 annotateline(b'p2', 3), |
63 ]) |
69 ]) |
64 |
70 |
65 childann = decorate(childdata, childfctx) |
71 childann = decorate(childdata, childfctx) |
66 childann = _annotatepair([p2ann, p1ann], childfctx, childann, False, |
72 childann = _annotatepair([p2ann, p1ann], childfctx, childann, False, |
67 diffopts) |
73 diffopts) |
68 self.assertEqual(childann[0], [ |
74 self.assertEqual(tr(childann), [ |
69 annotateline(b'old', 1), |
75 annotateline(b'old', 1), |
70 annotateline(b'c', 2), |
76 annotateline(b'c', 2), |
71 annotateline(b'p1', 3), |
77 annotateline(b'p1', 3), |
72 annotateline(b'c', 4), |
78 annotateline(b'c', 4), |
73 annotateline(b'p2', 3), |
79 annotateline(b'p2', 3), |
76 # Test with skipchild (note the difference caused by ordering) |
82 # Test with skipchild (note the difference caused by ordering) |
77 |
83 |
78 childann = decorate(childdata, childfctx) |
84 childann = decorate(childdata, childfctx) |
79 childann = _annotatepair([p1ann, p2ann], childfctx, childann, True, |
85 childann = _annotatepair([p1ann, p2ann], childfctx, childann, True, |
80 diffopts) |
86 diffopts) |
81 self.assertEqual(childann[0], [ |
87 self.assertEqual(tr(childann), [ |
82 annotateline(b'old', 1), |
88 annotateline(b'old', 1), |
83 annotateline(b'old', 2, True), |
89 annotateline(b'old', 2, True), |
84 # note that this line was carried over from earlier so it is *not* |
90 # note that this line was carried over from earlier so it is *not* |
85 # marked skipped |
91 # marked skipped |
86 annotateline(b'p2', 2), |
92 annotateline(b'p2', 2), |
89 ]) |
95 ]) |
90 |
96 |
91 childann = decorate(childdata, childfctx) |
97 childann = decorate(childdata, childfctx) |
92 childann = _annotatepair([p2ann, p1ann], childfctx, childann, True, |
98 childann = _annotatepair([p2ann, p1ann], childfctx, childann, True, |
93 diffopts) |
99 diffopts) |
94 self.assertEqual(childann[0], [ |
100 self.assertEqual(tr(childann), [ |
95 annotateline(b'old', 1), |
101 annotateline(b'old', 1), |
96 annotateline(b'old', 2, True), |
102 annotateline(b'old', 2, True), |
97 annotateline(b'p1', 3), |
103 annotateline(b'p1', 3), |
98 annotateline(b'p1', 3, True), |
104 annotateline(b'p1', 3, True), |
99 annotateline(b'p2', 3), |
105 annotateline(b'p2', 3), |