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, ('abSScdefghEE',)), ('abcdefgh', 3, 2, 3, ('abSScEE', 'SSdeEEf', 'gh')), ('abcdefgh', 2, 4, 1, ('ab', 'cd', 'SSefEE', 'SSgEEh')), ]: 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, f'S{w}S') ans.end = e ans.end_code = f'E{w}E' return ans highlights = [h(0, 1, 1), h(1, 3, 2)] self.ae(['S1SaE1ES2SbcE2Ed'], split_with_highlights('abcd', 10, highlights))
def h(s, e, w): ans = Segment(s, 'S{}S'.format(w)) ans.end = e ans.end_code = 'E{}E'.format(w) return ans
def h(s, e, w): ans = Segment(s, f'S{w}S') ans.end = e ans.end_code = f'E{w}E' return ans