Highlight changed in individual lines in chunks that have the same number of adds/removes

This commit is contained in:
Kovid Goyal
2018-05-04 15:35:11 +05:30
parent be9d876997
commit 51d2c01bc1
3 changed files with 70 additions and 11 deletions

View File

@@ -21,3 +21,14 @@ class TestDiff(BaseTest):
pc, sc = changed_center(left, right)
for src in (left, right):
self.assertEqual((prefix, suffix), (src[:pc], src[-sc:] if sc else ''))
def test_split_to_size(self):
from kittens.diff.render import split_to_size_with_center
for line, width, prefix_count, suffix_count, expected in [
('abcdefgh', 20, 2, 3, ('abSScdeEEfgh',)),
('abcdefgh', 20, 2, 0, ('abSScdefgh',)),
('abcdefgh', 3, 2, 3, ('abSSc', 'SSdeEEf', 'gh')),
('abcdefgh', 2, 4, 1, ('ab', 'cd', 'SSef', 'SSgEEh')),
]:
self.ae(expected, tuple(split_to_size_with_center(
line, width, prefix_count, suffix_count, 'SS', 'EE')))