mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-07 17:43:53 +02:00
diff kitten has working syntax highlighting
This commit is contained in:
@@ -22,13 +22,25 @@ class TestDiff(BaseTest):
|
||||
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
|
||||
def test_split_with_highlights(self):
|
||||
from kittens.diff.render import split_with_highlights, Segment, truncate_points
|
||||
self.ae(list(truncate_points('1234567890ab', 3)), [3, 6, 9])
|
||||
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')),
|
||||
('abcdefgh', 20, 2, 0, ('abSScdefghEE',)),
|
||||
('abcdefgh', 3, 2, 3, ('abSScEE', 'SSdeEEf', 'gh')),
|
||||
('abcdefgh', 2, 4, 1, ('ab', 'cd', 'SSefEE', 'SSgEEh')),
|
||||
]:
|
||||
self.ae(expected, tuple(split_to_size_with_center(
|
||||
line, width, prefix_count, suffix_count, 'SS', 'EE')))
|
||||
seg = Segment(prefix_count, 'SS')
|
||||
seg.end = len(line) - suffix_count
|
||||
seg.end_code = 'EE'
|
||||
self.ae(expected, tuple(split_with_highlights(line, width, [], seg)))
|
||||
|
||||
def h(s, e, w):
|
||||
ans = Segment(s, 'S{}S'.format(w))
|
||||
ans.end = e
|
||||
ans.end_code = 'E{}E'.format(w)
|
||||
return ans
|
||||
|
||||
highlights = [h(0, 1, 1), h(1, 3, 2)]
|
||||
self.ae(['S1SaE1ES2SbcE2Ed'], split_with_highlights('abcd', 10, highlights))
|
||||
|
||||
Reference in New Issue
Block a user