def test_get_region_map_index_style(self): line = "a test string that needs to be longer than 65 characters.........." s1 = IndexStyle([(1, 5), (4, 10), (15, 20), (35, 40), (45, 50)], ['red']) s2 = IndexStyle([(1, 3), (4, 6), (7, 14), (41, 44), (55, 60)], ['red']) s3 = IndexStyle([(60, 65)], ['red']) styles = [s1, s2, s3] region_map = self.lineStyleProcessor.get_region_map(line, styles) regions = region_map.keys() regions.sort() self.assert_results([(1, 5), (7, 14), (15, 20), (35, 40), (41, 44), (45, 50), (55, 60), (60, 65)], regions) # (60,65)? self.assertEqual(region_map[(1, 5)], s1) self.assertEqual(region_map[(7, 14)], s2) self.assertEqual(region_map[(15, 20)], s1) self.assertEqual(region_map[(35, 40)], s1) self.assertEqual(region_map[(41, 44)], s2) self.assertEqual(region_map[(45, 50)], s1) self.assertEqual(region_map[(55, 60)], s2) self.assertEqual(region_map[(60, 65)], s3)
def test_get_region_map_index_style_when_start_is_equal_to_line_length( self): line = "blip" region = (len(line), len(line) + 1) s1 = IndexStyle([region], ['red']) region_map = self.lineStyleProcessor.get_region_map(line, [s1]) regions = region_map.keys() self.assert_results([], regions)
def test_whole_line_style(self): input_line = "some text..." # <red>some text...<default> expected_output_line = "\033[31msome text...\033[m" self.assert_styled_line( [RegexStyle("some", ["red"], apply_to_whole_line=True)], input_line, expected_output_line) self.assert_styled_line( [RegexStyle("some text...", ["red"], apply_to_whole_line=False)], input_line, expected_output_line) self.assert_styled_line([IndexStyle([(0, len(input_line))], ["red"])], input_line, expected_output_line) # if end > line length, default to line length self.assert_styled_line([IndexStyle([(0, 99999)], ["red"])], input_line, expected_output_line)
def test_substring_style(self): input_line = "some text..." # <red>some<default> text...<default> expected_output_line = "\033[31msome\033[m text...\033[m" self.assert_styled_line([IndexStyle([(0, 4)], ["red"])], input_line, expected_output_line) self.assert_styled_line([RegexStyle("some", ["red"])], input_line, expected_output_line)
def test_get_region_map_index_style_when_end_is_none(self): line = "end is None, and therefore defaults to line length" region = (0, None) s1 = IndexStyle([region], ['red']) styles = [s1] region_map = self.lineStyleProcessor.get_region_map(line, styles) regions = region_map.keys() expected_end = len(line) self.assert_results([(0, expected_end)], regions) self.assertEqual(region_map[(0, expected_end)], s1)
def test_get_region_map_index_style_when_end_is_greater_than_line_length( self): # 01234567890123456 line = "a short string..." region = (7, 20) self.assertTrue(region[1] > len(line)) s1 = IndexStyle([region], ['red']) styles = [s1] region_map = self.lineStyleProcessor.get_region_map(line, styles) regions = region_map.keys() self.assert_results([(7, 17)], regions) self.assertEqual(region_map[(7, 17)], s1)
def expect_index_style(self, regions, transforms): self.expected_styles.append(IndexStyle(regions, transforms))