258
258
self.assertEquals(lines, ['z\n', 'c\n'])
260
260
origins = k1.annotate('text-c')
261
self.assertEquals(origins[0], ('text-c', 'z\n'))
262
self.assertEquals(origins[1], ('text-b', 'c\n'))
261
self.assertEquals(origins[0], ('text-c', 'z\n'))
262
self.assertEquals(origins[1], ('text-b', 'c\n'))
264
def test_extraction_reads_components_once(self):
265
t = MemoryTransport()
266
instrumented_t = TransportLogger(t)
267
k1 = KnitVersionedFile('id', instrumented_t, create=True, delta=True)
268
# should read the index
269
self.assertEqual([('id.kndx',)], instrumented_t._calls)
270
instrumented_t._calls = []
272
k1.add_lines('base', [], ['text\n'])
273
# should not have read at all
274
self.assertEqual([], instrumented_t._calls)
277
k1.add_lines('sub', ['base'], ['text\n', 'text2\n'])
278
# should not have read at all
279
self.assertEqual([], instrumented_t._calls)
283
# should not have read at all
284
self.assertEqual([], instrumented_t._calls)
291
# should have read a component
292
# should not have read the first component only
293
self.assertEqual([('id.knit', [(0, 87)])], instrumented_t._calls)
294
instrumented_t._calls = []
297
# should not have read at all
298
self.assertEqual([], instrumented_t._calls)
299
# and now read the other component
301
# should have read the second component
302
self.assertEqual([('id.knit', [(87, 92)])], instrumented_t._calls)
303
instrumented_t._calls = []
308
k1.add_lines('sub2', ['base'], ['text\n', 'text3\n'])
309
# should read the first component only
310
self.assertEqual([('id.knit', [(0, 87)])], instrumented_t._calls)
312
def test_iter_lines_reads_in_order(self):
313
t = MemoryTransport()
314
instrumented_t = TransportLogger(t)
315
k1 = KnitVersionedFile('id', instrumented_t, create=True, delta=True)
316
self.assertEqual([('id.kndx',)], instrumented_t._calls)
317
# add texts with no required ordering
318
k1.add_lines('base', [], ['text\n'])
319
k1.add_lines('base2', [], ['text2\n'])
321
instrumented_t._calls = []
322
# request a last-first iteration
323
results = list(k1.iter_lines_added_or_present_in_versions(['base2', 'base']))
324
self.assertEqual([('id.knit', [(0, 87), (87, 89)])], instrumented_t._calls)
325
self.assertEqual(['text\n', 'text2\n'], results)
264
327
def test_create_empty_annotated(self):
265
328
k1 = self.make_test_knit(True)