@@ -168,6 +168,67 @@ def test_gen_colors_keyword_highlighting(self):
168168 actual_highlights .append ((span_text , color .tag ))
169169 self .assertEqual (actual_highlights , expected_highlights )
170170
171+ def test_gen_colors_soft_keywords_after_blank_lines (self ):
172+ cases = [
173+ (
174+ "def f(): pass\n " ,
175+ "match -1:\n case _: pass" ,
176+ ["match" , "case" , "_" ],
177+ ),
178+ (
179+ "def f(): pass\n " ,
180+ "match value:\n case _: pass" ,
181+ ["match" , "case" , "_" ],
182+ ),
183+ (
184+ "match value:\n case 0: pass\n " ,
185+ " case -1: pass" ,
186+ ["match" , "case" , "case" ],
187+ ),
188+ (
189+ "match value:\n case 0: pass\n " ,
190+ " case other: pass" ,
191+ ["match" , "case" , "case" ],
192+ ),
193+ ("def f(): pass\n " , "type Alias = int" , ["type" ]),
194+ ("def f(): pass\n " , "lazy import mod" , ["lazy" ]),
195+ ("def f(): pass\n " , "lazy from mod import name" , ["lazy" ]),
196+ ]
197+ for prefix , statement , expected in cases :
198+ for blank_line in ("\n " , " \n " , "# comment\n " ):
199+ code = prefix + blank_line + statement
200+ with self .subTest (code = code ):
201+ actual = [
202+ code [color .span .start :color .span .end + 1 ]
203+ for color in gen_colors (code )
204+ if color .tag == "soft_keyword"
205+ ]
206+ self .assertEqual (actual , expected )
207+
208+ def test_gen_colors_match_after_dedent (self ):
209+ for subject in ("-1" , "value" ):
210+ for separator in ("" , "\n " , "# comment\n " ):
211+ code = (
212+ "if x:\n pass\n "
213+ f"{ separator } match { subject } :\n case _: pass"
214+ )
215+ with self .subTest (code = code ):
216+ actual = [
217+ code [color .span .start :color .span .end + 1 ]
218+ for color in gen_colors (code )
219+ if color .tag == "soft_keyword"
220+ ]
221+ self .assertEqual (actual , ["match" , "case" , "_" ])
222+
223+ def test_gen_colors_soft_keyword_names_in_brackets (self ):
224+ for opening , closing in ("()" , "[]" , "{}" ):
225+ for name in ("match" , "case" ):
226+ code = f"{ opening } \n { name } - 1\n { closing } "
227+ with self .subTest (code = code ):
228+ self .assertNotIn (
229+ "soft_keyword" , [color .tag for color in gen_colors (code )]
230+ )
231+
171232 def test_gen_colors_command_highlighting (self ):
172233 cases = [
173234 # highlights bare command names (after stripping whitespaces)
0 commit comments