~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: Martin Pool
  • Date: 2006-04-20 02:42:17 UTC
  • mfrom: (1674 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1675.
  • Revision ID: mbp@sourcefrog.net-20060420024217-e7530e10e384d5dd
[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
        k = KnitVersionedFile('test', LocalTransport('.'), delta=False, create=True)
90
90
        k.add_lines('text-1', [], ['a\n',    'b'  ])
91
91
        k.add_lines('text-2', ['text-1'], ['a\rb\n', 'b\n'])
 
92
        # reopening ensures maximum room for confusion
 
93
        k = KnitVersionedFile('test', LocalTransport('.'), delta=False, create=True)
92
94
        self.assertEquals(k.get_lines('text-1'), ['a\n',    'b'  ])
93
95
        self.assertEquals(k.get_lines('text-2'), ['a\rb\n', 'b\n'])
94
96
 
338
340
        # this tests that a new knit index file has the expected content
339
341
        # and that is writes the data we expect as records are added.
340
342
        knit = self.make_test_knit(True)
341
 
        self.assertFileEqual("# bzr knit index 7\n", 'test.kndx')
 
343
        self.assertFileEqual("# bzr knit index 8\n", 'test.kndx')
342
344
        knit.add_lines_with_ghosts('revid', ['a_ghost'], ['a\n'])
343
345
        self.assertFileEqual(
344
 
            "# bzr knit index 7\n"
 
346
            "# bzr knit index 8\n"
345
347
            "\n"
346
348
            "revid fulltext 0 84 .a_ghost :",
347
349
            'test.kndx')
348
350
        knit.add_lines_with_ghosts('revid2', ['revid'], ['a\n'])
349
351
        self.assertFileEqual(
350
 
            "# bzr knit index 7\n"
 
352
            "# bzr knit index 8\n"
351
353
            "\nrevid fulltext 0 84 .a_ghost :"
352
354
            "\nrevid2 line-delta 84 82 0 :",
353
355
            'test.kndx')
368
370
        self.assertEqual(['revid', 'revid2', 'revid3'], knit.versions())
369
371
        self.assertEqual(['revid2'], knit.get_parents('revid3'))
370
372
 
 
373
    def test_plan_merge(self):
 
374
        my_knit = self.make_test_knit(annotate=True)
 
375
        my_knit.add_lines('text1', [], split_lines(TEXT_1))
 
376
        my_knit.add_lines('text1a', ['text1'], split_lines(TEXT_1A))
 
377
        my_knit.add_lines('text1b', ['text1'], split_lines(TEXT_1B))
 
378
        plan = list(my_knit.plan_merge('text1a', 'text1b'))
 
379
        for plan_line, expected_line in zip(plan, AB_MERGE):
 
380
            self.assertEqual(plan_line, expected_line)
371
381
 
372
382
 
373
383
TEXT_1 = """\
388
398
- self-raising flour
389
399
"""
390
400
 
 
401
TEXT_1B = """\
 
402
Banana cup cake recipe
 
403
 
 
404
- bananas (do not use plantains!!!)
 
405
- broken tea cups
 
406
- flour
 
407
"""
 
408
 
391
409
delta_1_1a = """\
392
410
0,1,2
393
411
Banana cup cake recipe
406
424
- mushrooms
407
425
"""
408
426
 
 
427
AB_MERGE_TEXT="""unchanged|Banana cup cake recipe
 
428
new-a|(serves 6)
 
429
unchanged|
 
430
killed-b|- bananas
 
431
killed-b|- eggs
 
432
new-b|- bananas (do not use plantains!!!)
 
433
unchanged|- broken tea cups
 
434
new-a|- self-raising flour
 
435
new-b|- flour
 
436
"""
 
437
AB_MERGE=[tuple(l.split('|')) for l in AB_MERGE_TEXT.splitlines(True)]
 
438
 
 
439
 
409
440
def line_delta(from_lines, to_lines):
410
441
    """Generate line-based delta from one text to another"""
411
442
    s = difflib.SequenceMatcher(None, from_lines, to_lines)