142
162
def test_delta_against_multiple_sources(self):
143
163
di = self._gc_module.DeltaIndex()
144
first_text = ('a bit of text, that\n'
145
'does not have much in\n'
146
'common with the next text\n'
148
di.add_source(first_text)
164
di.add_source(_first_text, 0)
149
165
self.assertEqual(1, di._num_indexes)
150
166
self.assertEqual(1024, di._max_num_indexes)
151
self.assertEqual(len(first_text), di._source_offset)
152
second_text = ('some more bits of text\n'
153
'which does have a little bit in\n'
154
'common with the previous text\n'
156
di.add_source(second_text)
167
self.assertEqual(len(_first_text), di._source_offset)
168
di.add_source(_second_text, 0)
157
169
self.assertEqual(2, di._num_indexes)
158
170
self.assertEqual(1024, di._max_num_indexes)
159
self.assertEqual(len(first_text) + len(second_text), di._source_offset)
160
third_text = ('a bit of text, that\n'
161
'has some in common with the previous text\n'
163
'common with the next text\n'
165
delta = di.make_delta(third_text)
166
result = self._gc_module.apply_delta(first_text + second_text, delta)
167
self.assertEqualDiff(third_text, result)
171
self.assertEqual(len(_first_text) + len(_second_text), di._source_offset)
172
delta = di.make_delta(_third_text)
173
result = self._gc_module.apply_delta(_first_text + _second_text, delta)
174
self.assertEqualDiff(_third_text, result)
168
175
self.assertEqual('\x99\x01h\x90\x14\x0chas some in '
169
176
'\x91{\x1e\x07and not\x91!#', delta)
178
def test_delta_with_offsets(self):
179
di = self._gc_module.DeltaIndex()
180
di.add_source(_first_text, 5)
181
self.assertEqual(1, di._num_indexes)
182
self.assertEqual(1024, di._max_num_indexes)
183
self.assertEqual(len(_first_text) + 5, di._source_offset)
184
di.add_source(_second_text, 10)
185
self.assertEqual(2, di._num_indexes)
186
self.assertEqual(1024, di._max_num_indexes)
187
self.assertEqual(len(_first_text) + len(_second_text) + 15,
189
delta = di.make_delta(_third_text)
190
self.assertIsNot(None, delta)
191
result = self._gc_module.apply_delta(
192
'12345' + _first_text + '1234567890' + _second_text, delta)
193
self.assertIsNot(None, result)
194
self.assertEqualDiff(_third_text, result)
195
self.assertEqual('\xa8\x01h\x91\x05\x14\x0chas some in '
196
'\x91\x8a\x1e\x07and not\x91&#', delta)