~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-07-19 16:09:34 UTC
  • mfrom: (2520.4.135 bzr.mpbundle)
  • Revision ID: pqm@pqm.ubuntu.com-20070719160934-d51fyijw69oto88p
Add new bundle and merge-directive formats

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
    _KnitData,
42
42
    _KnitIndex,
43
43
    WeaveToKnit,
 
44
    KnitSequenceMatcher,
44
45
    )
45
46
from bzrlib.osutils import split_lines
46
47
from bzrlib.tests import TestCase, TestCaseWithTransport, Feature
916
917
    def test_delta(self):
917
918
        """Expression of knit delta as lines"""
918
919
        k = self.make_test_knit()
 
920
        KnitContent
919
921
        td = list(line_delta(TEXT_1.splitlines(True),
920
922
                             TEXT_1A.splitlines(True)))
921
923
        self.assertEqualDiff(''.join(td), delta_1_1a)
922
924
        out = apply_line_delta(TEXT_1.splitlines(True), td)
923
925
        self.assertEqualDiff(''.join(out), TEXT_1A)
924
926
 
 
927
    def assertDerivedBlocksEqual(self, source, target, noeol=False):
 
928
        """Assert that the derived matching blocks match real output"""
 
929
        source_lines = source.splitlines(True)
 
930
        target_lines = target.splitlines(True)
 
931
        def nl(line):
 
932
            if noeol and not line.endswith('\n'):
 
933
                return line + '\n'
 
934
            else:
 
935
                return line
 
936
        source_content = KnitContent([(None, nl(l)) for l in source_lines])
 
937
        target_content = KnitContent([(None, nl(l)) for l in target_lines])
 
938
        line_delta = source_content.line_delta(target_content)
 
939
        delta_blocks = list(KnitContent.get_line_delta_blocks(line_delta,
 
940
            source_lines, target_lines))
 
941
        matcher = KnitSequenceMatcher(None, source_lines, target_lines)
 
942
        matcher_blocks = list(list(matcher.get_matching_blocks()))
 
943
        self.assertEqual(matcher_blocks, delta_blocks)
 
944
 
 
945
    def test_get_line_delta_blocks(self):
 
946
        self.assertDerivedBlocksEqual('a\nb\nc\n', 'q\nc\n')
 
947
        self.assertDerivedBlocksEqual(TEXT_1, TEXT_1)
 
948
        self.assertDerivedBlocksEqual(TEXT_1, TEXT_1A)
 
949
        self.assertDerivedBlocksEqual(TEXT_1, TEXT_1B)
 
950
        self.assertDerivedBlocksEqual(TEXT_1B, TEXT_1A)
 
951
        self.assertDerivedBlocksEqual(TEXT_1A, TEXT_1B)
 
952
        self.assertDerivedBlocksEqual(TEXT_1A, '')
 
953
        self.assertDerivedBlocksEqual('', TEXT_1A)
 
954
        self.assertDerivedBlocksEqual('', '')
 
955
        self.assertDerivedBlocksEqual('a\nb\nc', 'a\nb\nc\nd')
 
956
 
 
957
    def test_get_line_delta_blocks_noeol(self):
 
958
        """Handle historical knit deltas safely
 
959
 
 
960
        Some existing knit deltas don't consider the last line to differ
 
961
        when the only difference whether it has a final newline.
 
962
 
 
963
        New knit deltas appear to always consider the last line to differ
 
964
        in this case.
 
965
        """
 
966
        self.assertDerivedBlocksEqual('a\nb\nc', 'a\nb\nc\nd\n', noeol=True)
 
967
        self.assertDerivedBlocksEqual('a\nb\nc\nd\n', 'a\nb\nc', noeol=True)
 
968
        self.assertDerivedBlocksEqual('a\nb\nc\n', 'a\nb\nc', noeol=True)
 
969
        self.assertDerivedBlocksEqual('a\nb\nc', 'a\nb\nc\n', noeol=True)
 
970
 
925
971
    def test_add_with_parents(self):
926
972
        """Store in knit with parents"""
927
973
        k = self.make_test_knit()