Skip to content

Commit

Permalink
Diff: Handle deletions on replacements
Browse files Browse the repository at this point in the history
Previously we assumed that if a line gets changed and the following
lines get deleted, the difflib generates two results for us. This is
wrong and this patch is the correction.

See #316
  • Loading branch information
sils committed Feb 23, 2015
1 parent 8feaff4 commit 861f344
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions coalib/results/Diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def from_string_arrays(cls, file_array_1, file_array_2):
file_array_2[b_index_1])
result.add_lines(a_index_1+1,
file_array_2[b_index_1+1:b_index_2])
for index in range(a_index_1+2, a_index_2+1):
result.delete_line(index)

return result

Expand Down
5 changes: 5 additions & 0 deletions coalib/tests/results/DiffTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ def test_from_string_arrays(self):
self.uut = Diff.from_string_arrays(a, b)
self.assertEqual(self.uut.apply(a), b)

a = ["first", "second", "third", "fourth"]
b = ["first_changed", "second_changed", "fourth"]
self.uut = Diff.from_string_arrays(a, b)
self.assertEqual(self.uut.apply(a), b)


if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit 861f344

Please sign in to comment.