1
# Copyright (C) 2007, 2009, 2011 Canonical Ltd
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
1
from unittest import TestCase
19
3
from bzrlib import (
48
30
multiparent.ParentText(0, 1, 2, 3)],
51
diff = multiparent.MultiParent.from_lines(LINES_2, [LINES_1])
52
self.assertEqual([multiparent.ParentText(0, 0, 0, 1),
53
multiparent.ParentText(0, 2, 1, 3)],
56
33
def test_compare_two_parents(self):
57
34
diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2, LINES_3])
58
35
self.assertEqual([multiparent.ParentText(1, 0, 0, 4),
59
36
multiparent.ParentText(0, 3, 4, 1)],
62
def test_compare_two_parents_blocks(self):
63
matcher = patiencediff.PatienceSequenceMatcher(None, LINES_2, LINES_1)
64
blocks = matcher.get_matching_blocks()
65
diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2, LINES_3],
67
self.assertEqual([multiparent.ParentText(1, 0, 0, 4),
68
multiparent.ParentText(0, 3, 4, 1)],
71
def test_get_matching_blocks(self):
72
diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2])
73
self.assertEqual([(0, 0, 1), (1, 2, 3), (4, 5, 0)],
74
list(diff.get_matching_blocks(0, len(LINES_2))))
76
diff = multiparent.MultiParent.from_lines(LINES_2, [LINES_1])
77
self.assertEqual([(0, 0, 1), (2, 1, 3), (5, 4, 0)],
78
list(diff.get_matching_blocks(0, len(LINES_1))))
80
39
def test_range_iterator(self):
81
40
diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2, LINES_3])
82
41
diff.hunks.append(multiparent.NewText(['q\n']))
108
67
self.assertEqual(multiparent.MultiParent(
109
68
[multiparent.NewText(['a\n']),
110
69
multiparent.ParentText(0, 1, 2, 3)]),
111
multiparent.MultiParent.from_patch('i 1\na\n\nc 0 1 2 3'))
70
multiparent.MultiParent.from_patch(
71
['i 1\n', 'a\n', '\n', 'c 0 1 2 3\n']))
112
72
self.assertEqual(multiparent.MultiParent(
113
73
[multiparent.NewText(['a']),
114
74
multiparent.ParentText(0, 1, 2, 3)]),
115
multiparent.MultiParent.from_patch('i 1\na\nc 0 1 2 3\n'))
117
def test_binary_content(self):
119
multiparent.MultiParent.from_lines(LF_SPLIT_LINES).to_patch())
120
multiparent.MultiParent.from_patch(''.join(patch))
122
def test_make_patch_from_binary(self):
123
patch = multiparent.MultiParent.from_texts(''.join(LF_SPLIT_LINES))
124
expected = multiparent.MultiParent([
125
multiparent.NewText(LF_SPLIT_LINES)])
126
self.assertEqual(expected, patch)
75
multiparent.MultiParent.from_patch(
76
['i 1\n', 'a\n', 'c 0 1 2 3\n']))
128
78
def test_num_lines(self):
129
79
mp = multiparent.MultiParent([multiparent.NewText(['a\n'])])
135
85
mp.hunks.append(multiparent.NewText(['f\n', 'g\n']))
136
86
self.assertEqual(7, mp.num_lines())
138
def test_to_lines(self):
139
mpdiff = multiparent.MultiParent.from_texts('a\nb\nc\n', ('b\nc\n',))
140
lines = mpdiff.to_lines(('b\ne\n',))
141
self.assertEqual(['a\n', 'b\n', 'e\n'], lines)
144
89
class TestNewText(TestCase):
203
148
self.assertEqual(REV_A, vf.get_line_list(['rev-a'])[0])
204
149
self.assertEqual([REV_B, REV_C], vf.get_line_list(['rev-b', 'rev-c']))
206
def test_reconstruct_empty(self):
207
vf = multiparent.MultiMemoryVersionedFile()
208
vf.add_version([], 'a', [])
209
self.assertEqual([], self.reconstruct_version(vf, 'a'))
212
152
def reconstruct(vf, revision_id, start, end):
213
153
reconstructor = multiparent._Reconstructor(vf, vf._lines,
265
205
def test_filenames(self):
266
206
vf = multiparent.MultiVersionedFile('foop')
267
207
vf.add_version('a\nb\nc\nd'.splitlines(True), 'a', [])
268
self.assertPathExists('foop.mpknit')
269
self.assertPathDoesNotExist('foop.mpidx')
208
self.failUnlessExists('foop.mpknit')
209
self.failIfExists('foop.mpidx')
271
self.assertPathExists('foop.mpidx')
211
self.failUnlessExists('foop.mpidx')
273
self.assertPathDoesNotExist('foop.mpknit')
274
self.assertPathDoesNotExist('foop.mpidx')
213
self.failIfExists('foop.mpknit')
214
self.failIfExists('foop.mpidx')