~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to multiparent/tests/test_multiparent.py

  • Committer: Aaron Bentley
  • Date: 2007-04-11 03:02:35 UTC
  • mto: (2520.4.1 bzr.mpbundle)
  • mto: This revision was merged to the branch mainline in revision 2631.
  • Revision ID: aaron.bentley@utoronto.ca-20070411030235-q8ngiatm1np64piq
Much progress on non-naive text reconstruction

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
                          multiparent.ParentText(0, 3, 4, 1)],
34
34
                         diff.hunks)
35
35
 
 
36
    def test_range_iterator(self):
 
37
        diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2, LINES_3])
 
38
        diff.hunks.append(multiparent.NewText(['q\n']))
 
39
        self.assertEqual([(0, 4, 'parent', (1, 0, 4)),
 
40
                          (4, 5, 'parent', (0, 3, 4)),
 
41
                          (5, 6, 'new', ['q\n'])],
 
42
                         list(diff.range_iterator()))
 
43
 
36
44
    def test_eq(self):
37
45
        diff = multiparent.MultiParent.from_lines(LINES_1)
38
46
        diff2 = multiparent.MultiParent.from_lines(LINES_1)
86
94
                         list(multiparent.ParentText(0, 1, 2, 3).to_patch()))
87
95
 
88
96
 
 
97
REV_A = ['a\n', 'b\n', 'c\n', 'd\n']
 
98
REV_B = ['a\n', 'c\n', 'd\n', 'e\n']
 
99
REV_C = ['a\n', 'b\n', 'e\n', 'f\n']
 
100
 
 
101
 
89
102
class TestVersionedFile(TestCase):
90
103
 
91
104
    def add_version(self, vf, text, version_id, parent_ids):
92
105
        vf.add_version([(t+'\n') for t in text], version_id, parent_ids)
93
106
 
94
 
    def test_add_version(self):
 
107
    def make_vf(self):
95
108
        vf = multiparent.MultiVersionedFile()
96
109
        self.add_version(vf, 'abcd', 'rev-a', [])
97
 
        self.assertEqual(vf._lines['rev-a'], ['a\n', 'b\n', 'c\n', 'd\n'])
 
110
        self.add_version(vf, 'acde', 'rev-b', [])
 
111
        self.add_version(vf, 'abef', 'rev-c', ['rev-a', 'rev-b'])
 
112
        return vf
 
113
 
 
114
    def test_add_version(self):
 
115
        vf = self.make_vf()
 
116
        self.assertEqual(REV_A, vf._lines['rev-a'])
98
117
        vf.clear_cache()
99
118
        self.assertEqual(vf._lines, {})
 
119
 
 
120
    def test_get_line_list(self):
 
121
        vf = self.make_vf()
 
122
        vf.clear_cache()
 
123
        self.assertEqual(REV_A, vf.get_line_list(['rev-a'])[0])
 
124
        self.assertEqual([REV_B, REV_C], vf.get_line_list(['rev-b', 'rev-c']))
 
125
 
 
126
    @staticmethod
 
127
    def reconstruct(vf, revision_id, start, end):
 
128
        reconstructor = multiparent._Reconstructor(vf._diffs, vf._lines,
 
129
                                                   vf._parents)
 
130
        lines = []
 
131
        reconstructor._reconstruct(lines, revision_id, start, end)
 
132
        return lines
 
133
 
 
134
    def test_reconstructor(self):
 
135
        vf = self.make_vf()
 
136
        self.assertEqual(['a\n', 'b\n'], self.reconstruct(vf, 'rev-a',  0, 2))
 
137
        self.assertEqual(['c\n', 'd\n'], self.reconstruct(vf, 'rev-a',  2, 4))
 
138
        self.assertEqual(['e\n', 'f\n'], self.reconstruct(vf, 'rev-c',  2, 4))