916
917
def test_delta(self):
917
918
"""Expression of knit delta as lines"""
918
919
k = self.make_test_knit()
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)
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)
932
if noeol and not line.endswith('\n'):
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)
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')
957
def test_get_line_delta_blocks_noeol(self):
958
"""Handle historical knit deltas safely
960
Some existing knit deltas don't consider the last line to differ
961
when the only difference whether it has a final newline.
963
New knit deltas appear to always consider the last line to differ
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)
925
971
def test_add_with_parents(self):
926
972
"""Store in knit with parents"""
927
973
k = self.make_test_knit()