@@ -4981,6 +4981,29 @@ def test_stack_entry(self):
49814981 p .set_trace (commands = ['w' , 'c' ])
49824982 self .assertIn ("\x1b " , output .getvalue ())
49834983
4984+ @unittest .skipIf (not pdb ._pyrepl_available (), "pyrepl is not available" )
4985+ def test_gen_colors (self ):
4986+ p = pdb .Pdb ()
4987+ gen_colors = p .pyrepl_input .gen_colors
4988+
4989+ test_cases = [
4990+ ("longlist" , [((0 , 7 ), "soft_keyword" )]),
4991+ ("!longlist" , [((0 , 0 ), "op" )]),
4992+ ("list" , [((0 , 3 ), "soft_keyword" )]),
4993+ ("list(" , [((0 , 3 ), "builtin" ), ((4 , 4 ), "op" )]),
4994+ ("a = 1" , [
4995+ ((0 , 0 ), "soft_keyword" ),
4996+ ((2 , 2 ), "op" ),
4997+ ((4 , 4 ), "number" ),
4998+ ])
4999+ ]
5000+
5001+ for buffer , expected in test_cases :
5002+ for color_span , ((start , end ), tag ) in zip (gen_colors (buffer ), expected , strict = True ):
5003+ self .assertEqual (color_span .span .start , start )
5004+ self .assertEqual (color_span .span .end , end )
5005+ self .assertEqual (color_span .tag , tag )
5006+
49845007
49855008@support .force_not_colorized_test_class
49865009@support .requires_subprocess ()
0 commit comments