|
1 | 1 | from unittest import TestCase |
2 | 2 |
|
3 | | -from _pyrepl.utils import str_width, wlen, prev_next_window |
| 3 | +from _pyrepl.utils import str_width, wlen, prev_next_window, gen_colors |
4 | 4 |
|
5 | 5 |
|
6 | 6 | class TestUtils(TestCase): |
@@ -60,3 +60,25 @@ def gen_raise(): |
60 | 60 | self.assertEqual(next(pnw), (3, 4, None)) |
61 | 61 | with self.assertRaises(ZeroDivisionError): |
62 | 62 | next(pnw) |
| 63 | + |
| 64 | + def test_gen_colors_keyword_highlighting(self): |
| 65 | + cases = [ |
| 66 | + # no highlights |
| 67 | + ("a.set", [(".", "op")]), |
| 68 | + ("obj.list", [(".", "op")]), |
| 69 | + ("obj.match", [(".", "op")]), |
| 70 | + ("b. \\\n format", [(".", "op")]), |
| 71 | + # highlights |
| 72 | + ("set", [("set", "builtin")]), |
| 73 | + ("list", [("list", "builtin")]), |
| 74 | + (" \n dict", [("dict", "builtin")]), |
| 75 | + ] |
| 76 | + for code, expected_highlights in cases: |
| 77 | + with self.subTest(code=code): |
| 78 | + colors = list(gen_colors(code)) |
| 79 | + # Extract (text, tag) pairs for comparison |
| 80 | + actual_highlights = [] |
| 81 | + for color in colors: |
| 82 | + span_text = code[color.span.start:color.span.end + 1] |
| 83 | + actual_highlights.append((span_text, color.tag)) |
| 84 | + self.assertEqual(actual_highlights, expected_highlights) |
0 commit comments