1
# Copyright (C) 2007 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 (
49
30
multiparent.ParentText(0, 1, 2, 3)],
52
diff = multiparent.MultiParent.from_lines(LINES_2, [LINES_1])
53
self.assertEqual([multiparent.ParentText(0, 0, 0, 1),
54
multiparent.ParentText(0, 2, 1, 3)],
57
33
def test_compare_two_parents(self):
58
34
diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2, LINES_3])
59
35
self.assertEqual([multiparent.ParentText(1, 0, 0, 4),
60
36
multiparent.ParentText(0, 3, 4, 1)],
63
def test_compare_two_parents_blocks(self):
64
matcher = patiencediff.PatienceSequenceMatcher(None, LINES_2, LINES_1)
65
blocks = matcher.get_matching_blocks()
66
diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2, LINES_3],
68
self.assertEqual([multiparent.ParentText(1, 0, 0, 4),
69
multiparent.ParentText(0, 3, 4, 1)],
72
def test_get_matching_blocks(self):
73
diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2])
74
self.assertEqual([(0, 0, 1), (1, 2, 3), (4, 5, 0)],
75
list(diff.get_matching_blocks(0, len(LINES_2))))
77
diff = multiparent.MultiParent.from_lines(LINES_2, [LINES_1])
78
self.assertEqual([(0, 0, 1), (2, 1, 3), (5, 4, 0)],
79
list(diff.get_matching_blocks(0, len(LINES_1))))
81
39
def test_range_iterator(self):
82
40
diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2, LINES_3])
83
41
diff.hunks.append(multiparent.NewText(['q\n']))
109
67
self.assertEqual(multiparent.MultiParent(
110
68
[multiparent.NewText(['a\n']),
111
69
multiparent.ParentText(0, 1, 2, 3)]),
112
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']))
113
72
self.assertEqual(multiparent.MultiParent(
114
73
[multiparent.NewText(['a']),
115
74
multiparent.ParentText(0, 1, 2, 3)]),
116
multiparent.MultiParent.from_patch('i 1\na\nc 0 1 2 3\n'))
118
def test_binary_content(self):
120
multiparent.MultiParent.from_lines(LF_SPLIT_LINES).to_patch())
121
multiparent.MultiParent.from_patch(''.join(patch))
123
def test_make_patch_from_binary(self):
124
patch = multiparent.MultiParent.from_texts(''.join(LF_SPLIT_LINES))
125
expected = multiparent.MultiParent([
126
multiparent.NewText(LF_SPLIT_LINES)])
127
self.assertEqual(expected, patch)
75
multiparent.MultiParent.from_patch(
76
['i 1\n', 'a\n', 'c 0 1 2 3\n']))
129
78
def test_num_lines(self):
130
79
mp = multiparent.MultiParent([multiparent.NewText(['a\n'])])
136
85
mp.hunks.append(multiparent.NewText(['f\n', 'g\n']))
137
86
self.assertEqual(7, mp.num_lines())
139
def test_to_lines(self):
140
mpdiff = multiparent.MultiParent.from_texts('a\nb\nc\n', ('b\nc\n',))
141
lines = mpdiff.to_lines(('b\ne\n',))
142
self.assertEqual(['a\n', 'b\n', 'e\n'], lines)
145
89
class TestNewText(TestCase):
204
148
self.assertEqual(REV_A, vf.get_line_list(['rev-a'])[0])
205
149
self.assertEqual([REV_B, REV_C], vf.get_line_list(['rev-b', 'rev-c']))
207
def test_reconstruct_empty(self):
208
vf = multiparent.MultiMemoryVersionedFile()
209
vf.add_version([], 'a', [])
210
self.assertEqual([], self.reconstruct_version(vf, 'a'))
213
152
def reconstruct(vf, revision_id, start, end):
214
153
reconstructor = multiparent._Reconstructor(vf, vf._lines,