bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
1711.2.16
by John Arbash Meinel
test_diff needs a copyright statement |
1 |
# Copyright (C) 2005, 2006 Canonical Development Ltd
|
2 |
#
|
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
||
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
|
1558.15.2
by Aaron Bentley
Implemented binary file handling for diff |
17 |
from cStringIO import StringIO |
18 |
||
19 |
from bzrlib.diff import internal_diff |
|
20 |
from bzrlib.errors import BinaryFile |
|
|
1711.2.20
by John Arbash Meinel
Late bind to patiencediff objects to make it easier to plug-in |
21 |
import bzrlib.patiencediff |
|
1185.81.14
by John Arbash Meinel
Added a main function for running cdvdifflib manually, included tests for unified_diff interfaces |
22 |
from bzrlib.tests import TestCase, TestCaseInTempDir |
|
1558.15.2
by Aaron Bentley
Implemented binary file handling for diff |
23 |
|
24 |
||
|
1558.15.11
by Aaron Bentley
Apply merge review suggestions |
25 |
def udiff_lines(old, new, allow_binary=False): |
|
974.1.6
by Aaron Bentley
Added unit tests |
26 |
output = StringIO() |
|
1558.15.11
by Aaron Bentley
Apply merge review suggestions |
27 |
internal_diff('old', old, 'new', new, output, allow_binary) |
|
974.1.6
by Aaron Bentley
Added unit tests |
28 |
output.seek(0, 0) |
29 |
return output.readlines() |
|
30 |
||
|
1185.81.25
by Aaron Bentley
Clean up test_diff |
31 |
|
|
1102
by Martin Pool
- merge test refactoring from robertc |
32 |
class TestDiff(TestCase): |
|
1185.81.25
by Aaron Bentley
Clean up test_diff |
33 |
|
|
1102
by Martin Pool
- merge test refactoring from robertc |
34 |
def test_add_nl(self): |
35 |
"""diff generates a valid diff for patches that add a newline""" |
|
|
974.1.6
by Aaron Bentley
Added unit tests |
36 |
lines = udiff_lines(['boo'], ['boo\n']) |
|
1185.16.145
by Martin Pool
Remove all assert statements from test cases. |
37 |
self.check_patch(lines) |
38 |
self.assertEquals(lines[4], '\\ No newline at end of file\n') |
|
39 |
## "expected no-nl, got %r" % lines[4]
|
|
|
974.1.6
by Aaron Bentley
Added unit tests |
40 |
|
|
1102
by Martin Pool
- merge test refactoring from robertc |
41 |
def test_add_nl_2(self): |
42 |
"""diff generates a valid diff for patches that change last line and |
|
43 |
add a newline.
|
|
44 |
"""
|
|
|
974.1.6
by Aaron Bentley
Added unit tests |
45 |
lines = udiff_lines(['boo'], ['goo\n']) |
|
1185.16.145
by Martin Pool
Remove all assert statements from test cases. |
46 |
self.check_patch(lines) |
47 |
self.assertEquals(lines[4], '\\ No newline at end of file\n') |
|
48 |
## "expected no-nl, got %r" % lines[4]
|
|
|
974.1.6
by Aaron Bentley
Added unit tests |
49 |
|
|
1102
by Martin Pool
- merge test refactoring from robertc |
50 |
def test_remove_nl(self): |
51 |
"""diff generates a valid diff for patches that change last line and |
|
52 |
add a newline.
|
|
53 |
"""
|
|
|
974.1.6
by Aaron Bentley
Added unit tests |
54 |
lines = udiff_lines(['boo\n'], ['boo']) |
|
1185.16.145
by Martin Pool
Remove all assert statements from test cases. |
55 |
self.check_patch(lines) |
56 |
self.assertEquals(lines[5], '\\ No newline at end of file\n') |
|
57 |
## "expected no-nl, got %r" % lines[5]
|
|
58 |
||
59 |
def check_patch(self, lines): |
|
60 |
self.assert_(len(lines) > 1) |
|
61 |
## "Not enough lines for a file header for patch:\n%s" % "".join(lines)
|
|
62 |
self.assert_(lines[0].startswith ('---')) |
|
63 |
## 'No orig line for patch:\n%s' % "".join(lines)
|
|
64 |
self.assert_(lines[1].startswith ('+++')) |
|
65 |
## 'No mod line for patch:\n%s' % "".join(lines)
|
|
66 |
self.assert_(len(lines) > 2) |
|
67 |
## "No hunks for patch:\n%s" % "".join(lines)
|
|
68 |
self.assert_(lines[2].startswith('@@')) |
|
69 |
## "No hunk header for patch:\n%s" % "".join(lines)
|
|
70 |
self.assert_('@@' in lines[2][2:]) |
|
71 |
## "Unterminated hunk header for patch:\n%s" % "".join(lines)
|
|
72 |
||
|
1558.15.2
by Aaron Bentley
Implemented binary file handling for diff |
73 |
def test_binary_lines(self): |
74 |
self.assertRaises(BinaryFile, udiff_lines, [1023 * 'a' + '\x00'], []) |
|
75 |
self.assertRaises(BinaryFile, udiff_lines, [], [1023 * 'a' + '\x00']) |
|
|
1558.15.11
by Aaron Bentley
Apply merge review suggestions |
76 |
udiff_lines([1023 * 'a' + '\x00'], [], allow_binary=True) |
77 |
udiff_lines([], [1023 * 'a' + '\x00'], allow_binary=True) |
|
|
1185.81.9
by John Arbash Meinel
Added (failing) tests for cdv.recurse_matches with common sections, |
78 |
|
|
1185.81.25
by Aaron Bentley
Clean up test_diff |
79 |
|
|
1711.2.15
by John Arbash Meinel
Found a couple CDV left |
80 |
class TestPatienceDiffLib(TestCase): |
|
1185.81.1
by John Arbash Meinel
Adding nofrillsprecisemerge's diff algorithm, wrapped in difflib. |
81 |
|
|
1185.81.9
by John Arbash Meinel
Added (failing) tests for cdv.recurse_matches with common sections, |
82 |
def test_unique_lcs(self): |
|
1711.2.20
by John Arbash Meinel
Late bind to patiencediff objects to make it easier to plug-in |
83 |
unique_lcs = bzrlib.patiencediff.unique_lcs |
|
1185.81.9
by John Arbash Meinel
Added (failing) tests for cdv.recurse_matches with common sections, |
84 |
self.assertEquals(unique_lcs('', ''), []) |
85 |
self.assertEquals(unique_lcs('a', 'a'), [(0,0)]) |
|
86 |
self.assertEquals(unique_lcs('a', 'b'), []) |
|
87 |
self.assertEquals(unique_lcs('ab', 'ab'), [(0,0), (1,1)]) |
|
88 |
self.assertEquals(unique_lcs('abcde', 'cdeab'), [(2,0), (3,1), (4,2)]) |
|
89 |
self.assertEquals(unique_lcs('cdeab', 'abcde'), [(0,2), (1,3), (2,4)]) |
|
90 |
self.assertEquals(unique_lcs('abXde', 'abYde'), [(0,0), (1,1), |
|
91 |
(3,3), (4,4)]) |
|
92 |
self.assertEquals(unique_lcs('acbac', 'abc'), [(2,1)]) |
|
93 |
||
94 |
def test_recurse_matches(self): |
|
95 |
def test_one(a, b, matches): |
|
96 |
test_matches = [] |
|
|
1711.2.22
by John Arbash Meinel
Passing the alo parameter to recurse_matches shaves of 5% of the diff time. |
97 |
bzrlib.patiencediff.recurse_matches(a, b, 0, 0, len(a), len(b), |
|
1711.2.20
by John Arbash Meinel
Late bind to patiencediff objects to make it easier to plug-in |
98 |
test_matches, 10) |
|
1185.81.9
by John Arbash Meinel
Added (failing) tests for cdv.recurse_matches with common sections, |
99 |
self.assertEquals(test_matches, matches) |
100 |
||
|
1711.2.17
by John Arbash Meinel
Small cleanups to patience_diff code. |
101 |
test_one(['a', '', 'b', '', 'c'], ['a', 'a', 'b', 'c', 'c'], |
|
1185.81.9
by John Arbash Meinel
Added (failing) tests for cdv.recurse_matches with common sections, |
102 |
[(0, 0), (2, 2), (4, 4)]) |
103 |
test_one(['a', 'c', 'b', 'a', 'c'], ['a', 'b', 'c'], |
|
104 |
[(0, 0), (2, 1), (4, 2)]) |
|
105 |
||
|
1185.81.14
by John Arbash Meinel
Added a main function for running cdvdifflib manually, included tests for unified_diff interfaces |
106 |
# recurse_matches doesn't match non-unique
|
107 |
# lines surrounded by bogus text.
|
|
|
1185.81.24
by Aaron Bentley
Reoganize patience-related code |
108 |
# The update has been done in patiencediff.SequenceMatcher instead
|
|
1185.81.14
by John Arbash Meinel
Added a main function for running cdvdifflib manually, included tests for unified_diff interfaces |
109 |
|
110 |
# This is what it could be
|
|
|
1185.81.9
by John Arbash Meinel
Added (failing) tests for cdv.recurse_matches with common sections, |
111 |
#test_one('aBccDe', 'abccde', [(0,0), (2,2), (3,3), (5,5)])
|
|
1185.81.14
by John Arbash Meinel
Added a main function for running cdvdifflib manually, included tests for unified_diff interfaces |
112 |
|
|
1185.81.9
by John Arbash Meinel
Added (failing) tests for cdv.recurse_matches with common sections, |
113 |
# This is what it currently gives:
|
114 |
test_one('aBccDe', 'abccde', [(0,0), (5,5)]) |
|
115 |
||
|
1185.81.1
by John Arbash Meinel
Adding nofrillsprecisemerge's diff algorithm, wrapped in difflib. |
116 |
def test_matching_blocks(self): |
|
1711.2.10
by John Arbash Meinel
Clarify the patience tests a little bit. |
117 |
def chk_blocks(a, b, expected_blocks): |
|
1185.81.1
by John Arbash Meinel
Adding nofrillsprecisemerge's diff algorithm, wrapped in difflib. |
118 |
# difflib always adds a signature of the total
|
119 |
# length, with no matching entries at the end
|
|
|
1711.2.20
by John Arbash Meinel
Late bind to patiencediff objects to make it easier to plug-in |
120 |
s = bzrlib.patiencediff.PatienceSequenceMatcher(None, a, b) |
|
1185.81.11
by John Arbash Meinel
Found some edge cases that weren't being matched. |
121 |
blocks = s.get_matching_blocks() |
|
1711.2.10
by John Arbash Meinel
Clarify the patience tests a little bit. |
122 |
self.assertEquals((len(a), len(b), 0), blocks[-1]) |
123 |
self.assertEquals(expected_blocks, blocks[:-1]) |
|
|
1185.81.1
by John Arbash Meinel
Adding nofrillsprecisemerge's diff algorithm, wrapped in difflib. |
124 |
|
|
1185.81.2
by John Arbash Meinel
A couple small tests. |
125 |
# Some basic matching tests
|
|
1185.81.1
by John Arbash Meinel
Adding nofrillsprecisemerge's diff algorithm, wrapped in difflib. |
126 |
chk_blocks('', '', []) |
127 |
chk_blocks([], [], []) |
|
128 |
chk_blocks('abcd', 'abcd', [(0, 0, 4)]) |
|
129 |
chk_blocks('abcd', 'abce', [(0, 0, 3)]) |
|
130 |
chk_blocks('eabc', 'abce', [(1, 0, 3)]) |
|
131 |
chk_blocks('eabce', 'abce', [(1, 0, 4)]) |
|
132 |
chk_blocks('abcde', 'abXde', [(0, 0, 2), (3, 3, 2)]) |
|
|
1185.81.3
by John Arbash Meinel
Adding tests for checking opcodes. |
133 |
chk_blocks('abcde', 'abXYZde', [(0, 0, 2), (3, 5, 2)]) |
134 |
chk_blocks('abde', 'abXYZde', [(0, 0, 2), (2, 5, 2)]) |
|
135 |
# This may check too much, but it checks to see that
|
|
136 |
# a copied block stays attached to the previous section,
|
|
137 |
# not the later one.
|
|
138 |
# difflib would tend to grab the trailing longest match
|
|
139 |
# which would make the diff not look right
|
|
|
1185.81.9
by John Arbash Meinel
Added (failing) tests for cdv.recurse_matches with common sections, |
140 |
chk_blocks('abcdefghijklmnop', 'abcdefxydefghijklmnop', |
141 |
[(0, 0, 6), (6, 11, 10)]) |
|
|
1185.81.1
by John Arbash Meinel
Adding nofrillsprecisemerge's diff algorithm, wrapped in difflib. |
142 |
|
|
1185.81.2
by John Arbash Meinel
A couple small tests. |
143 |
# make sure it supports passing in lists
|
144 |
chk_blocks( |
|
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
145 |
['hello there\n', |
146 |
'world\n', |
|
147 |
'how are you today?\n'], |
|
148 |
['hello there\n', |
|
149 |
'how are you today?\n'], |
|
|
1185.81.2
by John Arbash Meinel
A couple small tests. |
150 |
[(0, 0, 1), (2, 1, 1)]) |
|
1185.81.1
by John Arbash Meinel
Adding nofrillsprecisemerge's diff algorithm, wrapped in difflib. |
151 |
|
|
1711.2.21
by John Arbash Meinel
Cleanup patiencediff, remove the use of difflib.SequenceMatcher. |
152 |
# non unique lines surrounded by non-matching lines
|
153 |
# won't be found
|
|
154 |
chk_blocks('aBccDe', 'abccde', [(0,0,1), (5,5,1)]) |
|
155 |
||
156 |
# But they only need to be locally unique
|
|
157 |
chk_blocks('aBcDec', 'abcdec', [(0,0,1), (2,2,1), (4,4,2)]) |
|
158 |
||
159 |
# non unique blocks won't be matched
|
|
160 |
chk_blocks('aBcdEcdFg', 'abcdecdfg', [(0,0,1), (8,8,1)]) |
|
161 |
||
162 |
# but locally unique ones will
|
|
163 |
chk_blocks('aBcdEeXcdFg', 'abcdecdfg', [(0,0,1), (2,2,2), |
|
164 |
(5,4,1), (7,5,2), (10,8,1)]) |
|
165 |
||
166 |
chk_blocks('abbabbXd', 'cabbabxd', [(7,7,1)]) |
|
167 |
chk_blocks('abbabbbb', 'cabbabbc', []) |
|
168 |
chk_blocks('bbbbbbbb', 'cbbbbbbc', []) |
|
|
1185.81.11
by John Arbash Meinel
Found some edge cases that weren't being matched. |
169 |
|
|
1185.81.3
by John Arbash Meinel
Adding tests for checking opcodes. |
170 |
def test_opcodes(self): |
|
1711.2.10
by John Arbash Meinel
Clarify the patience tests a little bit. |
171 |
def chk_ops(a, b, expected_codes): |
|
1711.2.20
by John Arbash Meinel
Late bind to patiencediff objects to make it easier to plug-in |
172 |
s = bzrlib.patiencediff.PatienceSequenceMatcher(None, a, b) |
|
1711.2.10
by John Arbash Meinel
Clarify the patience tests a little bit. |
173 |
self.assertEquals(expected_codes, s.get_opcodes()) |
|
1185.81.3
by John Arbash Meinel
Adding tests for checking opcodes. |
174 |
|
175 |
chk_ops('', '', []) |
|
176 |
chk_ops([], [], []) |
|
|
1185.81.9
by John Arbash Meinel
Added (failing) tests for cdv.recurse_matches with common sections, |
177 |
chk_ops('abcd', 'abcd', [('equal', 0,4, 0,4)]) |
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
178 |
chk_ops('abcd', 'abce', [('equal', 0,3, 0,3), |
179 |
('replace', 3,4, 3,4) |
|
180 |
])
|
|
181 |
chk_ops('eabc', 'abce', [('delete', 0,1, 0,0), |
|
182 |
('equal', 1,4, 0,3), |
|
183 |
('insert', 4,4, 3,4) |
|
184 |
])
|
|
185 |
chk_ops('eabce', 'abce', [('delete', 0,1, 0,0), |
|
186 |
('equal', 1,5, 0,4) |
|
|
1185.81.3
by John Arbash Meinel
Adding tests for checking opcodes. |
187 |
])
|
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
188 |
chk_ops('abcde', 'abXde', [('equal', 0,2, 0,2), |
189 |
('replace', 2,3, 2,3), |
|
190 |
('equal', 3,5, 3,5) |
|
|
1185.81.3
by John Arbash Meinel
Adding tests for checking opcodes. |
191 |
])
|
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
192 |
chk_ops('abcde', 'abXYZde', [('equal', 0,2, 0,2), |
193 |
('replace', 2,3, 2,5), |
|
194 |
('equal', 3,5, 5,7) |
|
|
1185.81.3
by John Arbash Meinel
Adding tests for checking opcodes. |
195 |
])
|
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
196 |
chk_ops('abde', 'abXYZde', [('equal', 0,2, 0,2), |
197 |
('insert', 2,2, 2,5), |
|
198 |
('equal', 2,4, 5,7) |
|
|
1185.81.3
by John Arbash Meinel
Adding tests for checking opcodes. |
199 |
])
|
200 |
chk_ops('abcdefghijklmnop', 'abcdefxydefghijklmnop', |
|
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
201 |
[('equal', 0,6, 0,6), |
202 |
('insert', 6,6, 6,11), |
|
203 |
('equal', 6,16, 11,21) |
|
|
1185.81.3
by John Arbash Meinel
Adding tests for checking opcodes. |
204 |
])
|
205 |
chk_ops( |
|
206 |
[ 'hello there\n' |
|
207 |
, 'world\n' |
|
208 |
, 'how are you today?\n'], |
|
209 |
[ 'hello there\n' |
|
210 |
, 'how are you today?\n'], |
|
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
211 |
[('equal', 0,1, 0,1), |
212 |
('delete', 1,2, 1,1), |
|
|
1711.2.21
by John Arbash Meinel
Cleanup patiencediff, remove the use of difflib.SequenceMatcher. |
213 |
('equal', 2,3, 1,2), |
|
1185.81.9
by John Arbash Meinel
Added (failing) tests for cdv.recurse_matches with common sections, |
214 |
])
|
215 |
chk_ops('aBccDe', 'abccde', |
|
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
216 |
[('equal', 0,1, 0,1), |
|
1711.2.21
by John Arbash Meinel
Cleanup patiencediff, remove the use of difflib.SequenceMatcher. |
217 |
('replace', 1,5, 1,5), |
218 |
('equal', 5,6, 5,6), |
|
219 |
])
|
|
220 |
chk_ops('aBcDec', 'abcdec', |
|
221 |
[('equal', 0,1, 0,1), |
|
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
222 |
('replace', 1,2, 1,2), |
|
1711.2.21
by John Arbash Meinel
Cleanup patiencediff, remove the use of difflib.SequenceMatcher. |
223 |
('equal', 2,3, 2,3), |
224 |
('replace', 3,4, 3,4), |
|
225 |
('equal', 4,6, 4,6), |
|
|
1185.81.3
by John Arbash Meinel
Adding tests for checking opcodes. |
226 |
])
|
|
1185.81.10
by John Arbash Meinel
Added some more test cases. |
227 |
chk_ops('aBcdEcdFg', 'abcdecdfg', |
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
228 |
[('equal', 0,1, 0,1), |
|
1711.2.21
by John Arbash Meinel
Cleanup patiencediff, remove the use of difflib.SequenceMatcher. |
229 |
('replace', 1,8, 1,8), |
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
230 |
('equal', 8,9, 8,9) |
|
1185.81.10
by John Arbash Meinel
Added some more test cases. |
231 |
])
|
|
1711.2.21
by John Arbash Meinel
Cleanup patiencediff, remove the use of difflib.SequenceMatcher. |
232 |
chk_ops('aBcdEeXcdFg', 'abcdecdfg', |
233 |
[('equal', 0,1, 0,1), |
|
234 |
('replace', 1,2, 1,2), |
|
235 |
('equal', 2,4, 2,4), |
|
236 |
('delete', 4,5, 4,4), |
|
237 |
('equal', 5,6, 4,5), |
|
238 |
('delete', 6,7, 5,5), |
|
239 |
('equal', 7,9, 5,7), |
|
240 |
('replace', 9,10, 7,8), |
|
241 |
('equal', 10,11, 8,9) |
|
242 |
])
|
|
|
1185.81.10
by John Arbash Meinel
Added some more test cases. |
243 |
|
|
1185.81.16
by John Arbash Meinel
Added tests, and an assert check to make sure ranges are always increasing. |
244 |
def test_multiple_ranges(self): |
245 |
# There was an earlier bug where we used a bad set of ranges,
|
|
246 |
# this triggers that specific bug, to make sure it doesn't regress
|
|
|
1711.2.10
by John Arbash Meinel
Clarify the patience tests a little bit. |
247 |
def chk_blocks(a, b, expected_blocks): |
|
1185.81.16
by John Arbash Meinel
Added tests, and an assert check to make sure ranges are always increasing. |
248 |
# difflib always adds a signature of the total
|
249 |
# length, with no matching entries at the end
|
|
|
1711.2.20
by John Arbash Meinel
Late bind to patiencediff objects to make it easier to plug-in |
250 |
s = bzrlib.patiencediff.PatienceSequenceMatcher(None, a, b) |
|
1185.81.16
by John Arbash Meinel
Added tests, and an assert check to make sure ranges are always increasing. |
251 |
blocks = s.get_matching_blocks() |
252 |
x = blocks.pop() |
|
253 |
self.assertEquals(x, (len(a), len(b), 0)) |
|
|
1711.2.10
by John Arbash Meinel
Clarify the patience tests a little bit. |
254 |
self.assertEquals(expected_blocks, blocks) |
|
1185.81.16
by John Arbash Meinel
Added tests, and an assert check to make sure ranges are always increasing. |
255 |
|
256 |
chk_blocks('abcdefghijklmnop' |
|
257 |
, 'abcXghiYZQRSTUVWXYZijklmnop' |
|
258 |
, [(0, 0, 3), (6, 4, 3), (9, 20, 7)]) |
|
259 |
||
260 |
chk_blocks('ABCd efghIjk L' |
|
261 |
, 'AxyzBCn mo pqrstuvwI1 2 L' |
|
|
1711.2.21
by John Arbash Meinel
Cleanup patiencediff, remove the use of difflib.SequenceMatcher. |
262 |
, [(0,0,1), (1, 4, 2), (9, 19, 1), (12, 23, 3)]) |
|
1185.81.16
by John Arbash Meinel
Added tests, and an assert check to make sure ranges are always increasing. |
263 |
|
|
1711.2.8
by John Arbash Meinel
rot13 the code snippet to help with clarity. |
264 |
# These are rot13 code snippets.
|
|
1185.81.16
by John Arbash Meinel
Added tests, and an assert check to make sure ranges are always increasing. |
265 |
chk_blocks('''\ |
|
1711.2.8
by John Arbash Meinel
rot13 the code snippet to help with clarity. |
266 |
trg nqqrq jura lbh nqq n svyr va gur qverpgbel.
|
267 |
"""
|
|
268 |
gnxrf_netf = ['svyr*']
|
|
269 |
gnxrf_bcgvbaf = ['ab-erphefr']
|
|
270 |
|
|
271 |
qrs eha(frys, svyr_yvfg, ab_erphefr=Snyfr):
|
|
272 |
sebz omeyvo.nqq vzcbeg fzneg_nqq, nqq_ercbegre_cevag, nqq_ercbegre_ahyy
|
|
273 |
vs vf_dhvrg():
|
|
274 |
ercbegre = nqq_ercbegre_ahyy
|
|
275 |
ryfr:
|
|
276 |
ercbegre = nqq_ercbegre_cevag
|
|
277 |
fzneg_nqq(svyr_yvfg, abg ab_erphefr, ercbegre)
|
|
278 |
||
279 |
||
280 |
pynff pzq_zxqve(Pbzznaq):
|
|
281 |
'''.splitlines(True), '''\ |
|
282 |
trg nqqrq jura lbh nqq n svyr va gur qverpgbel.
|
|
283 |
||
284 |
--qel-eha jvyy fubj juvpu svyrf jbhyq or nqqrq, ohg abg npghnyyl
|
|
285 |
nqq gurz.
|
|
286 |
"""
|
|
287 |
gnxrf_netf = ['svyr*']
|
|
288 |
gnxrf_bcgvbaf = ['ab-erphefr', 'qel-eha']
|
|
289 |
||
290 |
qrs eha(frys, svyr_yvfg, ab_erphefr=Snyfr, qel_eha=Snyfr):
|
|
291 |
vzcbeg omeyvo.nqq
|
|
292 |
||
293 |
vs qel_eha:
|
|
294 |
vs vf_dhvrg():
|
|
295 |
# Guvf vf cbvagyrff, ohg V'q engure abg envfr na reebe
|
|
296 |
npgvba = omeyvo.nqq.nqq_npgvba_ahyy
|
|
297 |
ryfr:
|
|
298 |
npgvba = omeyvo.nqq.nqq_npgvba_cevag
|
|
299 |
ryvs vf_dhvrg():
|
|
300 |
npgvba = omeyvo.nqq.nqq_npgvba_nqq
|
|
301 |
ryfr:
|
|
302 |
npgvba = omeyvo.nqq.nqq_npgvba_nqq_naq_cevag
|
|
303 |
||
304 |
omeyvo.nqq.fzneg_nqq(svyr_yvfg, abg ab_erphefr, npgvba)
|
|
305 |
||
306 |
||
307 |
pynff pzq_zxqve(Pbzznaq):
|
|
|
1185.81.16
by John Arbash Meinel
Added tests, and an assert check to make sure ranges are always increasing. |
308 |
'''.splitlines(True) |
309 |
, [(0,0,1), (1, 4, 2), (9, 19, 1), (12, 23, 3)]) |
|
310 |
||
|
1711.2.9
by John Arbash Meinel
Rename cdv => patience |
311 |
def test_patience_unified_diff(self): |
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
312 |
txt_a = ['hello there\n', |
313 |
'world\n', |
|
314 |
'how are you today?\n'] |
|
315 |
txt_b = ['hello there\n', |
|
316 |
'how are you today?\n'] |
|
|
1711.2.20
by John Arbash Meinel
Late bind to patiencediff objects to make it easier to plug-in |
317 |
unified_diff = bzrlib.patiencediff.unified_diff |
318 |
psm = bzrlib.patiencediff.PatienceSequenceMatcher |
|
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
319 |
self.assertEquals([ '--- \n', |
320 |
'+++ \n', |
|
321 |
'@@ -1,3 +1,2 @@\n', |
|
322 |
' hello there\n', |
|
323 |
'-world\n', |
|
324 |
' how are you today?\n' |
|
|
1185.81.14
by John Arbash Meinel
Added a main function for running cdvdifflib manually, included tests for unified_diff interfaces |
325 |
]
|
|
1711.2.20
by John Arbash Meinel
Late bind to patiencediff objects to make it easier to plug-in |
326 |
, list(unified_diff(txt_a, txt_b, |
327 |
sequencematcher=psm))) |
|
|
1185.81.14
by John Arbash Meinel
Added a main function for running cdvdifflib manually, included tests for unified_diff interfaces |
328 |
txt_a = map(lambda x: x+'\n', 'abcdefghijklmnop') |
329 |
txt_b = map(lambda x: x+'\n', 'abcdefxydefghijklmnop') |
|
330 |
# This is the result with LongestCommonSubstring matching
|
|
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
331 |
self.assertEquals(['--- \n', |
332 |
'+++ \n', |
|
333 |
'@@ -1,6 +1,11 @@\n', |
|
334 |
' a\n', |
|
335 |
' b\n', |
|
336 |
' c\n', |
|
337 |
'+d\n', |
|
338 |
'+e\n', |
|
339 |
'+f\n', |
|
340 |
'+x\n', |
|
341 |
'+y\n', |
|
342 |
' d\n', |
|
343 |
' e\n', |
|
344 |
' f\n'] |
|
|
1185.81.14
by John Arbash Meinel
Added a main function for running cdvdifflib manually, included tests for unified_diff interfaces |
345 |
, list(unified_diff(txt_a, txt_b))) |
|
1711.2.9
by John Arbash Meinel
Rename cdv => patience |
346 |
# And the patience diff
|
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
347 |
self.assertEquals(['--- \n', |
348 |
'+++ \n', |
|
349 |
'@@ -4,6 +4,11 @@\n', |
|
350 |
' d\n', |
|
351 |
' e\n', |
|
352 |
' f\n', |
|
353 |
'+x\n', |
|
354 |
'+y\n', |
|
355 |
'+d\n', |
|
356 |
'+e\n', |
|
357 |
'+f\n', |
|
358 |
' g\n', |
|
359 |
' h\n', |
|
360 |
' i\n', |
|
|
1185.81.14
by John Arbash Meinel
Added a main function for running cdvdifflib manually, included tests for unified_diff interfaces |
361 |
]
|
|
1185.81.25
by Aaron Bentley
Clean up test_diff |
362 |
, list(unified_diff(txt_a, txt_b, |
|
1711.2.20
by John Arbash Meinel
Late bind to patiencediff objects to make it easier to plug-in |
363 |
sequencematcher=psm))) |
|
1185.81.25
by Aaron Bentley
Clean up test_diff |
364 |
|
|
1185.81.14
by John Arbash Meinel
Added a main function for running cdvdifflib manually, included tests for unified_diff interfaces |
365 |
|
|
1711.2.15
by John Arbash Meinel
Found a couple CDV left |
366 |
class TestPatienceDiffLibFiles(TestCaseInTempDir): |
|
1185.81.14
by John Arbash Meinel
Added a main function for running cdvdifflib manually, included tests for unified_diff interfaces |
367 |
|
|
1711.2.9
by John Arbash Meinel
Rename cdv => patience |
368 |
def test_patience_unified_diff_files(self): |
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
369 |
txt_a = ['hello there\n', |
370 |
'world\n', |
|
371 |
'how are you today?\n'] |
|
372 |
txt_b = ['hello there\n', |
|
373 |
'how are you today?\n'] |
|
|
1185.81.14
by John Arbash Meinel
Added a main function for running cdvdifflib manually, included tests for unified_diff interfaces |
374 |
open('a1', 'wb').writelines(txt_a) |
375 |
open('b1', 'wb').writelines(txt_b) |
|
376 |
||
|
1711.2.20
by John Arbash Meinel
Late bind to patiencediff objects to make it easier to plug-in |
377 |
unified_diff_files = bzrlib.patiencediff.unified_diff_files |
378 |
psm = bzrlib.patiencediff.PatienceSequenceMatcher |
|
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
379 |
self.assertEquals(['--- a1 \n', |
380 |
'+++ b1 \n', |
|
381 |
'@@ -1,3 +1,2 @@\n', |
|
382 |
' hello there\n', |
|
383 |
'-world\n', |
|
384 |
' how are you today?\n', |
|
|
1185.81.14
by John Arbash Meinel
Added a main function for running cdvdifflib manually, included tests for unified_diff interfaces |
385 |
]
|
|
1185.81.25
by Aaron Bentley
Clean up test_diff |
386 |
, list(unified_diff_files('a1', 'b1', |
|
1711.2.20
by John Arbash Meinel
Late bind to patiencediff objects to make it easier to plug-in |
387 |
sequencematcher=psm))) |
|
1185.81.14
by John Arbash Meinel
Added a main function for running cdvdifflib manually, included tests for unified_diff interfaces |
388 |
|
389 |
txt_a = map(lambda x: x+'\n', 'abcdefghijklmnop') |
|
390 |
txt_b = map(lambda x: x+'\n', 'abcdefxydefghijklmnop') |
|
391 |
open('a2', 'wb').writelines(txt_a) |
|
392 |
open('b2', 'wb').writelines(txt_b) |
|
393 |
||
394 |
# This is the result with LongestCommonSubstring matching
|
|
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
395 |
self.assertEquals(['--- a2 \n', |
396 |
'+++ b2 \n', |
|
397 |
'@@ -1,6 +1,11 @@\n', |
|
398 |
' a\n', |
|
399 |
' b\n', |
|
400 |
' c\n', |
|
401 |
'+d\n', |
|
402 |
'+e\n', |
|
403 |
'+f\n', |
|
404 |
'+x\n', |
|
405 |
'+y\n', |
|
406 |
' d\n', |
|
407 |
' e\n', |
|
408 |
' f\n'] |
|
|
1185.81.14
by John Arbash Meinel
Added a main function for running cdvdifflib manually, included tests for unified_diff interfaces |
409 |
, list(unified_diff_files('a2', 'b2'))) |
410 |
||
|
1711.2.9
by John Arbash Meinel
Rename cdv => patience |
411 |
# And the patience diff
|
|
1185.81.29
by Aaron Bentley
Fix style issues and duplicated tests |
412 |
self.assertEquals(['--- a2 \n', |
413 |
'+++ b2 \n', |
|
414 |
'@@ -4,6 +4,11 @@\n', |
|
415 |
' d\n', |
|
416 |
' e\n', |
|
417 |
' f\n', |
|
418 |
'+x\n', |
|
419 |
'+y\n', |
|
420 |
'+d\n', |
|
421 |
'+e\n', |
|
422 |
'+f\n', |
|
423 |
' g\n', |
|
424 |
' h\n', |
|
425 |
' i\n', |
|
|
1185.81.14
by John Arbash Meinel
Added a main function for running cdvdifflib manually, included tests for unified_diff interfaces |
426 |
]
|
|
1185.81.25
by Aaron Bentley
Clean up test_diff |
427 |
, list(unified_diff_files('a2', 'b2', |
|
1711.2.20
by John Arbash Meinel
Late bind to patiencediff objects to make it easier to plug-in |
428 |
sequencematcher=psm))) |