author | Martin von Zweigbergk <martinvonz@google.com> |
Wed, 01 Aug 2018 22:32:51 -0700 | |
changeset 38823 | a9a4b0fc1e5d |
parent 38809 | 57af5ee15b35 |
child 38924 | 6fed8b323651 |
permissions | -rw-r--r-- |
38795
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1 |
from __future__ import absolute_import, print_function |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
2 |
|
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
3 |
import difflib |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
4 |
import random |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
5 |
import unittest |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
6 |
|
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
7 |
from mercurial import linelog |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
8 |
|
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
9 |
maxlinenum = 0xffffff |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
10 |
maxb1 = 0xffffff |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
11 |
maxdeltaa = 10 |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
12 |
maxdeltab = 10 |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
13 |
|
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
14 |
def _genedits(seed, endrev): |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
15 |
lines = [] |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
16 |
random.seed(seed) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
17 |
rev = 0 |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
18 |
for rev in range(0, endrev): |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
19 |
n = len(lines) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
20 |
a1 = random.randint(0, n) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
21 |
a2 = random.randint(a1, min(n, a1 + maxdeltaa)) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
22 |
b1 = random.randint(0, maxb1) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
23 |
b2 = random.randint(b1, b1 + maxdeltab) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
24 |
blines = [(rev, idx) for idx in range(b1, b2)] |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
25 |
lines[a1:a2] = blines |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
26 |
yield lines, rev, a1, a2, b1, b2 |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
27 |
|
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
28 |
class linelogtests(unittest.TestCase): |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
29 |
def testlinelogencodedecode(self): |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
30 |
program = [linelog._eof(0, 0), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
31 |
linelog._jge(41, 42), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
32 |
linelog._jump(0, 43), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
33 |
linelog._eof(0, 0), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
34 |
linelog._jl(44, 45), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
35 |
linelog._line(46, 47), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
36 |
] |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
37 |
ll = linelog.linelog(program, maxrev=100) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
38 |
enc = ll.encode() |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
39 |
# round-trips okay |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
40 |
self.assertEqual(linelog.linelog.fromdata(enc)._program, ll._program) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
41 |
self.assertEqual(linelog.linelog.fromdata(enc), ll) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
42 |
# This encoding matches the encoding used by hg-experimental's |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
43 |
# linelog file, or is supposed to if it doesn't. |
38809
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
44 |
self.assertEqual(enc, (b'\x00\x00\x01\x90\x00\x00\x00\x06' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
45 |
b'\x00\x00\x00\xa4\x00\x00\x00*' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
46 |
b'\x00\x00\x00\x00\x00\x00\x00+' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
47 |
b'\x00\x00\x00\x00\x00\x00\x00\x00' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
48 |
b'\x00\x00\x00\xb1\x00\x00\x00-' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
49 |
b'\x00\x00\x00\xba\x00\x00\x00/')) |
38795
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
50 |
|
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
51 |
def testsimpleedits(self): |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
52 |
ll = linelog.linelog() |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
53 |
# Initial revision: add lines 0, 1, and 2 |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
54 |
ll.replacelines(1, 0, 0, 0, 3) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
55 |
self.assertEqual([(l.rev, l.linenum) for l in ll.annotate(1)], |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
56 |
[(1, 0), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
57 |
(1, 1), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
58 |
(1, 2), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
59 |
]) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
60 |
# Replace line 1 with a new line |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
61 |
ll.replacelines(2, 1, 2, 1, 2) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
62 |
self.assertEqual([(l.rev, l.linenum) for l in ll.annotate(2)], |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
63 |
[(1, 0), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
64 |
(2, 1), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
65 |
(1, 2), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
66 |
]) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
67 |
# delete a line out of 2 |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
68 |
ll.replacelines(3, 1, 2, 0, 0) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
69 |
self.assertEqual([(l.rev, l.linenum) for l in ll.annotate(3)], |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
70 |
[(1, 0), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
71 |
(1, 2), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
72 |
]) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
73 |
# annotation of 1 is unchanged |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
74 |
self.assertEqual([(l.rev, l.linenum) for l in ll.annotate(1)], |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
75 |
[(1, 0), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
76 |
(1, 1), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
77 |
(1, 2), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
78 |
]) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
79 |
ll.annotate(3) # set internal state to revision 3 |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
80 |
start = ll.getoffset(0) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
81 |
end = ll.getoffset(1) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
82 |
self.assertEqual(ll.getalllines(start, end), [ |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
83 |
(1, 0), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
84 |
(2, 1), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
85 |
(1, 1), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
86 |
]) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
87 |
self.assertEqual(ll.getalllines(), [ |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
88 |
(1, 0), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
89 |
(2, 1), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
90 |
(1, 1), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
91 |
(1, 2), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
92 |
]) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
93 |
|
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
94 |
def testparseclinelogfile(self): |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
95 |
# This data is what the replacements in testsimpleedits |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
96 |
# produce when fed to the original linelog.c implementation. |
38809
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
97 |
data = (b'\x00\x00\x00\x0c\x00\x00\x00\x0f' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
98 |
b'\x00\x00\x00\x00\x00\x00\x00\x02' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
99 |
b'\x00\x00\x00\x05\x00\x00\x00\x06' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
100 |
b'\x00\x00\x00\x06\x00\x00\x00\x00' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
101 |
b'\x00\x00\x00\x00\x00\x00\x00\x07' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
102 |
b'\x00\x00\x00\x06\x00\x00\x00\x02' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
103 |
b'\x00\x00\x00\x00\x00\x00\x00\x00' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
104 |
b'\x00\x00\x00\t\x00\x00\x00\t' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
105 |
b'\x00\x00\x00\x00\x00\x00\x00\x0c' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
106 |
b'\x00\x00\x00\x08\x00\x00\x00\x05' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
107 |
b'\x00\x00\x00\x06\x00\x00\x00\x01' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
108 |
b'\x00\x00\x00\x00\x00\x00\x00\x05' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
109 |
b'\x00\x00\x00\x0c\x00\x00\x00\x05' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
110 |
b'\x00\x00\x00\n\x00\x00\x00\x01' |
57af5ee15b35
linelog: port to Python 3
Augie Fackler <augie@google.com>
parents:
38795
diff
changeset
|
111 |
b'\x00\x00\x00\x00\x00\x00\x00\t') |
38795
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
112 |
llc = linelog.linelog.fromdata(data) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
113 |
self.assertEqual([(l.rev, l.linenum) for l in llc.annotate(1)], |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
114 |
[(1, 0), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
115 |
(1, 1), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
116 |
(1, 2), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
117 |
]) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
118 |
self.assertEqual([(l.rev, l.linenum) for l in llc.annotate(2)], |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
119 |
[(1, 0), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
120 |
(2, 1), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
121 |
(1, 2), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
122 |
]) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
123 |
self.assertEqual([(l.rev, l.linenum) for l in llc.annotate(3)], |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
124 |
[(1, 0), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
125 |
(1, 2), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
126 |
]) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
127 |
# Check we emit the same bytecode. |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
128 |
ll = linelog.linelog() |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
129 |
# Initial revision: add lines 0, 1, and 2 |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
130 |
ll.replacelines(1, 0, 0, 0, 3) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
131 |
# Replace line 1 with a new line |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
132 |
ll.replacelines(2, 1, 2, 1, 2) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
133 |
# delete a line out of 2 |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
134 |
ll.replacelines(3, 1, 2, 0, 0) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
135 |
diff = '\n ' + '\n '.join(difflib.unified_diff( |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
136 |
ll.debugstr().splitlines(), llc.debugstr().splitlines(), |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
137 |
'python', 'c', lineterm='')) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
138 |
self.assertEqual(ll._program, llc._program, 'Program mismatch: ' + diff) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
139 |
# Done as a secondary step so we get a better result if the |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
140 |
# program is where the mismatch is. |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
141 |
self.assertEqual(ll, llc) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
142 |
self.assertEqual(ll.encode(), data) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
143 |
|
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
144 |
def testanothersimplecase(self): |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
145 |
ll = linelog.linelog() |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
146 |
ll.replacelines(3, 0, 0, 0, 2) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
147 |
ll.replacelines(4, 0, 2, 0, 0) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
148 |
self.assertEqual([(l.rev, l.linenum) for l in ll.annotate(4)], |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
149 |
[]) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
150 |
self.assertEqual([(l.rev, l.linenum) for l in ll.annotate(3)], |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
151 |
[(3, 0), (3, 1)]) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
152 |
# rev 2 is empty because contents were only ever introduced in rev 3 |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
153 |
self.assertEqual([(l.rev, l.linenum) for l in ll.annotate(2)], |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
154 |
[]) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
155 |
|
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
156 |
def testrandomedits(self): |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
157 |
# Inspired by original linelog tests. |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
158 |
seed = random.random() |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
159 |
numrevs = 2000 |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
160 |
ll = linelog.linelog() |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
161 |
# Populate linelog |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
162 |
for lines, rev, a1, a2, b1, b2 in _genedits(seed, numrevs): |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
163 |
ll.replacelines(rev, a1, a2, b1, b2) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
164 |
ar = ll.annotate(rev) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
165 |
self.assertEqual(ll.annotateresult, lines) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
166 |
# Verify we can get back these states by annotating each rev |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
167 |
for lines, rev, a1, a2, b1, b2 in _genedits(seed, numrevs): |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
168 |
ar = ll.annotate(rev) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
169 |
self.assertEqual([(l.rev, l.linenum) for l in ar], lines) |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
170 |
|
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
171 |
if __name__ == '__main__': |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
172 |
import silenttestrunner |
422d661056be
linelog: add a Python implementation of the linelog datastructure
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
173 |
silenttestrunner.main(__name__) |