@@ -159,3 +159,64 @@ def test_gen_colors_keyword_highlighting(self):
159159 span_text = code [color .span .start :color .span .end + 1 ]
160160 actual_highlights .append ((span_text , color .tag ))
161161 self .assertEqual (actual_highlights , expected_highlights )
162+
163+ def test_gen_colors_soft_keywords_after_blank_lines (self ):
164+ cases = [
165+ (
166+ "def f(): pass\n " ,
167+ "match -1:\n case _: pass" ,
168+ ["match" , "case" , "_" ],
169+ ),
170+ (
171+ "def f(): pass\n " ,
172+ "match value:\n case _: pass" ,
173+ ["match" , "case" , "_" ],
174+ ),
175+ (
176+ "match value:\n case 0: pass\n " ,
177+ " case -1: pass" ,
178+ ["match" , "case" , "case" ],
179+ ),
180+ (
181+ "match value:\n case 0: pass\n " ,
182+ " case other: pass" ,
183+ ["match" , "case" , "case" ],
184+ ),
185+ ("def f(): pass\n " , "type Alias = int" , ["type" ]),
186+ ("def f(): pass\n " , "lazy import mod" , ["lazy" ]),
187+ ("def f(): pass\n " , "lazy from mod import name" , ["lazy" ]),
188+ ]
189+ for prefix , statement , expected in cases :
190+ for blank_line in ("\n " , " \n " , "# comment\n " ):
191+ code = prefix + blank_line + statement
192+ with self .subTest (code = code ):
193+ actual = [
194+ code [color .span .start :color .span .end + 1 ]
195+ for color in gen_colors (code )
196+ if color .tag == "soft_keyword"
197+ ]
198+ self .assertEqual (actual , expected )
199+
200+ def test_gen_colors_match_after_dedent (self ):
201+ for subject in ("-1" , "value" ):
202+ for separator in ("" , "\n " , "# comment\n " ):
203+ code = (
204+ "if x:\n pass\n "
205+ f"{ separator } match { subject } :\n case _: pass"
206+ )
207+ with self .subTest (code = code ):
208+ actual = [
209+ code [color .span .start :color .span .end + 1 ]
210+ for color in gen_colors (code )
211+ if color .tag == "soft_keyword"
212+ ]
213+ self .assertEqual (actual , ["match" , "case" , "_" ])
214+
215+ def test_gen_colors_soft_keyword_names_in_brackets (self ):
216+ for opening , closing in ("()" , "[]" , "{}" ):
217+ for name in ("match" , "case" ):
218+ code = f"{ opening } \n { name } - 1\n { closing } "
219+ with self .subTest (code = code ):
220+ self .assertNotIn (
221+ "soft_keyword" , [color .tag for color in gen_colors (code )]
222+ )
0 commit comments