~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_versionedfile.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-06-05 06:34:59 UTC
  • mfrom: (3468.2.7 234748-integrated)
  • Revision ID: pqm@pqm.ubuntu.com-20080605063459-2lk0v0sayzfqsbqw
(mbp) #234748 fix problems in final newline on Knit add_lines and
        get_lines

Show diffs side-by-side

added added

removed removed

Lines of Context:
530
530
        self.assertRaises(errors.ReservedId, vf.get_lines, 'b:')
531
531
        self.assertRaises(errors.ReservedId, vf.get_text, 'b:')
532
532
 
 
533
    def test_add_unchanged_last_line_noeol_snapshot(self):
 
534
        """Add a text with an unchanged last line with no eol should work."""
 
535
        # Test adding this in a number of chain lengths; because the interface
 
536
        # for VersionedFile does not allow forcing a specific chain length, we
 
537
        # just use a small base to get the first snapshot, then a much longer
 
538
        # first line for the next add (which will make the third add snapshot)
 
539
        # and so on. 20 has been chosen as an aribtrary figure - knits use 200
 
540
        # as a capped delta length, but ideally we would have some way of
 
541
        # tuning the test to the store (e.g. keep going until a snapshot
 
542
        # happens).
 
543
        for length in range(20):
 
544
            version_lines = {}
 
545
            vf = self.get_file('case-%d' % length)
 
546
            prefix = 'step-%d'
 
547
            parents = []
 
548
            for step in range(length):
 
549
                version = prefix % step
 
550
                lines = (['prelude \n'] * step) + ['line']
 
551
                vf.add_lines(version, parents, lines)
 
552
                version_lines[version] = lines
 
553
                parents = [version]
 
554
            vf.add_lines('no-eol', parents, ['line'])
 
555
            vf.get_texts(version_lines.keys())
 
556
            self.assertEqualDiff('line', vf.get_text('no-eol'))
 
557
 
 
558
    def test_get_texts_eol_variation(self):
 
559
        # similar to the failure in <http://bugs.launchpad.net/234748>
 
560
        vf = self.get_file()
 
561
        sample_text_nl = ["line\n"]
 
562
        sample_text_no_nl = ["line"]
 
563
        versions = []
 
564
        version_lines = {}
 
565
        parents = []
 
566
        for i in range(4):
 
567
            version = 'v%d' % i
 
568
            if i % 2:
 
569
                lines = sample_text_nl
 
570
            else:
 
571
                lines = sample_text_no_nl
 
572
            # left_matching blocks is an internal api; it operates on the
 
573
            # *internal* representation for a knit, which is with *all* lines
 
574
            # being normalised to end with \n - even the final line in a no_nl
 
575
            # file. Using it here ensures that a broken internal implementation
 
576
            # (which is what this test tests) will generate a correct line
 
577
            # delta (which is to say, an empty delta).
 
578
            vf.add_lines(version, parents, lines,
 
579
                left_matching_blocks=[(0, 0, 1)])
 
580
            parents = [version]
 
581
            versions.append(version)
 
582
            version_lines[version] = lines
 
583
        vf.check()
 
584
        vf.get_texts(versions)
 
585
        vf.get_texts(reversed(versions))
 
586
 
 
587
    def test_add_lines_with_matching_blocks_noeol_last_line(self):
 
588
        """Add a text with an unchanged last line with no eol should work."""
 
589
        from bzrlib import multiparent
 
590
        # Hand verified sha1 of the text we're adding.
 
591
        sha1 = '6a1d115ec7b60afb664dc14890b5af5ce3c827a4'
 
592
        # Create a mpdiff which adds a new line before the trailing line, and
 
593
        # reuse the last line unaltered (which can cause annotation reuse).
 
594
        # Test adding this in two situations:
 
595
        # On top of a new insertion
 
596
        vf = self.get_file('fulltext')
 
597
        vf.add_lines('noeol', [], ['line'])
 
598
        vf.add_lines('noeol2', ['noeol'], ['newline\n', 'line'],
 
599
            left_matching_blocks=[(0, 1, 1)])
 
600
        self.assertEqualDiff('newline\nline', vf.get_text('noeol2'))
 
601
        # On top of a delta
 
602
        vf = self.get_file('delta')
 
603
        vf.add_lines('base', [], ['line'])
 
604
        vf.add_lines('noeol', ['base'], ['prelude\n', 'line'])
 
605
        vf.add_lines('noeol2', ['noeol'], ['newline\n', 'line'],
 
606
            left_matching_blocks=[(1, 1, 1)])
 
607
        self.assertEqualDiff('newline\nline', vf.get_text('noeol2'))
 
608
 
533
609
    def test_make_mpdiffs(self):
534
610
        from bzrlib import multiparent
535
611
        vf = self.get_file('foo')