| 1 |
import unittest |
| 2 |
|
| 3 |
from mercurial import ( |
| 4 |
mdiff, |
| 5 |
pycompat, |
| 6 |
) |
| 7 |
from mercurial.utils.dag_util import ( |
| 8 |
annotateline, |
| 9 |
_annotatedfile, |
| 10 |
_annotatepair, |
| 11 |
) |
| 12 |
|
| 13 |
|
| 14 |
def tr(a): |
| 15 |
return [ |
| 16 |
annotateline(fctx, lineno, skip) |
| 17 |
for fctx, lineno, skip in zip(a.fctxs, a.linenos, a.skips) |
| 18 |
] |
| 19 |
|
| 20 |
|
| 21 |
class AnnotateTests(unittest.TestCase): |
| 22 |
"""Unit tests for annotate code.""" |
| 23 |
|
| 24 |
def testannotatepair(self): |
| 25 |
self.maxDiff = None # camelcase-required |
| 26 |
|
| 27 |
oldfctx = b'old' |
| 28 |
p1fctx, p2fctx, childfctx = b'p1', b'p2', b'c' |
| 29 |
olddata = b'a\nb\n' |
| 30 |
p1data = b'a\nb\nc\n' |
| 31 |
p2data = b'a\nc\nd\n' |
| 32 |
childdata = b'a\nb2\nc\nc2\nd\n' |
| 33 |
diffopts = mdiff.diffopts() |
| 34 |
|
| 35 |
def decorate(text, fctx): |
| 36 |
n = text.count(b'\n') |
| 37 |
linenos = pycompat.rangelist(1, n + 1) |
| 38 |
return _annotatedfile([fctx] * n, linenos, [False] * n, text) |
| 39 |
|
| 40 |
# Basic usage |
| 41 |
|
| 42 |
oldann = decorate(olddata, oldfctx) |
| 43 |
p1ann = decorate(p1data, p1fctx) |
| 44 |
p1ann = _annotatepair([oldann], p1fctx, p1ann, False, diffopts) |
| 45 |
self.assertEqual( |
| 46 |
tr(p1ann), |
| 47 |
[ |
| 48 |
annotateline(b'old', 1), |
| 49 |
annotateline(b'old', 2), |
| 50 |
annotateline(b'p1', 3), |
| 51 |
], |
| 52 |
) |
| 53 |
|
| 54 |
p2ann = decorate(p2data, p2fctx) |
| 55 |
p2ann = _annotatepair([oldann], p2fctx, p2ann, False, diffopts) |
| 56 |
self.assertEqual( |
| 57 |
tr(p2ann), |
| 58 |
[ |
| 59 |
annotateline(b'old', 1), |
| 60 |
annotateline(b'p2', 2), |
| 61 |
annotateline(b'p2', 3), |
| 62 |
], |
| 63 |
) |
| 64 |
|
| 65 |
# Test with multiple parents (note the difference caused by ordering) |
| 66 |
|
| 67 |
childann = decorate(childdata, childfctx) |
| 68 |
childann = _annotatepair( |
| 69 |
[p1ann, p2ann], childfctx, childann, False, diffopts |
| 70 |
) |
| 71 |
self.assertEqual( |
| 72 |
tr(childann), |
| 73 |
[ |
| 74 |
annotateline(b'old', 1), |
| 75 |
annotateline(b'c', 2), |
| 76 |
annotateline(b'p2', 2), |
| 77 |
annotateline(b'c', 4), |
| 78 |
annotateline(b'p2', 3), |
| 79 |
], |
| 80 |
) |
| 81 |
|
| 82 |
childann = decorate(childdata, childfctx) |
| 83 |
childann = _annotatepair( |
| 84 |
[p2ann, p1ann], childfctx, childann, False, diffopts |
| 85 |
) |
| 86 |
self.assertEqual( |
| 87 |
tr(childann), |
| 88 |
[ |
| 89 |
annotateline(b'old', 1), |
| 90 |
annotateline(b'c', 2), |
| 91 |
annotateline(b'p1', 3), |
| 92 |
annotateline(b'c', 4), |
| 93 |
annotateline(b'p2', 3), |
| 94 |
], |
| 95 |
) |
| 96 |
|
| 97 |
# Test with skipchild (note the difference caused by ordering) |
| 98 |
|
| 99 |
childann = decorate(childdata, childfctx) |
| 100 |
childann = _annotatepair( |
| 101 |
[p1ann, p2ann], childfctx, childann, True, diffopts |
| 102 |
) |
| 103 |
self.assertEqual( |
| 104 |
tr(childann), |
| 105 |
[ |
| 106 |
annotateline(b'old', 1), |
| 107 |
annotateline(b'old', 2, True), |
| 108 |
# note that this line was carried over from earlier so it is *not* |
| 109 |
# marked skipped |
| 110 |
annotateline(b'p2', 2), |
| 111 |
annotateline(b'p2', 2, True), |
| 112 |
annotateline(b'p2', 3), |
| 113 |
], |
| 114 |
) |
| 115 |
|
| 116 |
childann = decorate(childdata, childfctx) |
| 117 |
childann = _annotatepair( |
| 118 |
[p2ann, p1ann], childfctx, childann, True, diffopts |
| 119 |
) |
| 120 |
self.assertEqual( |
| 121 |
tr(childann), |
| 122 |
[ |
| 123 |
annotateline(b'old', 1), |
| 124 |
annotateline(b'old', 2, True), |
| 125 |
annotateline(b'p1', 3), |
| 126 |
annotateline(b'p1', 3, True), |
| 127 |
annotateline(b'p2', 3), |
| 128 |
], |
| 129 |
) |
| 130 |
|
| 131 |
|
| 132 |
if __name__ == '__main__': |
| 133 |
import silenttestrunner |
| 134 |
|
| 135 |
silenttestrunner.main(__name__) |