@@ -127,3 +127,62 @@ def test_gen_colors_keyword_highlighting(self):
127127 span_text = code [color .span .start :color .span .end + 1 ]
128128 actual_highlights .append ((span_text , color .tag ))
129129 self .assertEqual (actual_highlights , expected_highlights )
130+
131+ def test_gen_colors_soft_keywords_after_blank_lines (self ):
132+ cases = [
133+ (
134+ "def f(): pass\n " ,
135+ "match -1:\n case _: pass" ,
136+ ["match" , "case" , "_" ],
137+ ),
138+ (
139+ "def f(): pass\n " ,
140+ "match value:\n case _: pass" ,
141+ ["match" , "case" , "_" ],
142+ ),
143+ (
144+ "match value:\n case 0: pass\n " ,
145+ " case -1: pass" ,
146+ ["match" , "case" , "case" ],
147+ ),
148+ (
149+ "match value:\n case 0: pass\n " ,
150+ " case other: pass" ,
151+ ["match" , "case" , "case" ],
152+ ),
153+ ("def f(): pass\n " , "type Alias = int" , ["type" ]),
154+ ]
155+ for prefix , statement , expected in cases :
156+ for blank_line in ("\n " , " \n " , "# comment\n " ):
157+ code = prefix + blank_line + statement
158+ with self .subTest (code = code ):
159+ actual = [
160+ code [color .span .start :color .span .end + 1 ]
161+ for color in gen_colors (code )
162+ if color .tag == "soft_keyword"
163+ ]
164+ self .assertEqual (actual , expected )
165+
166+ def test_gen_colors_match_after_dedent (self ):
167+ for subject in ("-1" , "value" ):
168+ for separator in ("" , "\n " , "# comment\n " ):
169+ code = (
170+ "if x:\n pass\n "
171+ f"{ separator } match { subject } :\n case _: pass"
172+ )
173+ with self .subTest (code = code ):
174+ actual = [
175+ code [color .span .start :color .span .end + 1 ]
176+ for color in gen_colors (code )
177+ if color .tag == "soft_keyword"
178+ ]
179+ self .assertEqual (actual , ["match" , "case" , "_" ])
180+
181+ def test_gen_colors_soft_keyword_names_in_brackets (self ):
182+ for opening , closing in ("()" , "[]" , "{}" ):
183+ for name in ("match" , "case" ):
184+ code = f"{ opening } \n { name } - 1\n { closing } "
185+ with self .subTest (code = code ):
186+ self .assertNotIn (
187+ "soft_keyword" , [color .tag for color in gen_colors (code )]
188+ )
0 commit comments