1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
from unittest import TestCase
import multiparent
LINES_1 = "a\nb\nc\nd\ne\n".splitlines(True)
LINES_2 = "a\nc\nd\ne\n".splitlines(True)
LINES_3 = "a\nb\nc\nd\n".splitlines(True)
class Mock(object):
def __init__(self, **kwargs):
self.__dict__ = kwargs
class TestMulti(TestCase):
def test_compare_no_parent(self):
diff = multiparent.MultiParent.from_lines(LINES_1)
self.assertEqual([multiparent.NewText(LINES_1)], diff.hunks)
def test_compare_one_parent(self):
diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2])
self.assertEqual([multiparent.ParentText(0, 0, 0, 1),
multiparent.NewText(['b\n']),
multiparent.ParentText(0, 1, 2, 3)],
diff.hunks)
def test_compare_two_parents(self):
diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2, LINES_3])
self.assertEqual([multiparent.ParentText(1, 0, 0, 4),
multiparent.ParentText(0, 3, 4, 1)],
diff.hunks)
def test_eq(self):
diff = multiparent.MultiParent.from_lines(LINES_1)
diff2 = multiparent.MultiParent.from_lines(LINES_1)
self.assertEqual(diff, diff2)
diff3 = multiparent.MultiParent.from_lines(LINES_2)
self.assertFalse(diff == diff3)
self.assertFalse(diff == Mock(hunks=[multiparent.NewText(LINES_1)]))
self.assertEqual(multiparent.MultiParent(
[multiparent.NewText(LINES_1),
multiparent.ParentText(0, 1, 2, 3)]),
multiparent.MultiParent(
[multiparent.NewText(LINES_1),
multiparent.ParentText(0, 1, 2, 3)]))
def test_to_patch(self):
self.assertEqual(['i 1\n', 'a\n', '\n', 'c 0 1 2 3\n'],
list(multiparent.MultiParent([multiparent.NewText(['a\n']),
multiparent.ParentText(0, 1, 2, 3)]).to_patch()))
class TestNewText(TestCase):
def test_eq(self):
self.assertEqual(multiparent.NewText([]), multiparent.NewText([]))
self.assertFalse(multiparent.NewText(['a']) ==
multiparent.NewText(['b']))
self.assertFalse(multiparent.NewText(['a']) == Mock(lines=['a']))
def test_to_patch(self):
self.assertEqual(['i 0\n', '\n'],
list(multiparent.NewText([]).to_patch()))
self.assertEqual(['i 1\n', 'a', '\n'],
list(multiparent.NewText(['a']).to_patch()))
self.assertEqual(['i 1\n', 'a\n', '\n'],
list(multiparent.NewText(['a\n']).to_patch()))
class TestParentText(TestCase):
def test_eq(self):
self.assertEqual(multiparent.ParentText(1, 2, 3, 4),
multiparent.ParentText(1, 2, 3, 4))
self.assertFalse(multiparent.ParentText(1, 2, 3, 4) ==
multiparent.ParentText(2, 2, 3, 4))
self.assertFalse(multiparent.ParentText(1, 2, 3, 4) ==
Mock(parent=1, parent_pos=2, child_pos=3,
num_lines=4))
def test_to_patch(self):
self.assertEqual(['c 0 1 2 3\n'],
list(multiparent.ParentText(0, 1, 2, 3).to_patch()))
class TestVersionedFile(TestCase):
def add_version(self, vf, text, version_id, parent_ids):
vf.add_version([(t+'\n') for t in text], version_id, parent_ids)
def test_add_version(self):
vf = multiparent.MultiVersionedFile()
self.add_version(vf, 'abcd', 'rev-a', [])
self.assertEqual(vf._lines['rev-a'], ['a\n', 'b\n', 'c\n', 'd\n'])
vf.clear_cache()
self.assertEqual(vf._lines, {})
|