@@ -136,10 +136,82 @@ def test_debug_specifier(self):
136136 # Test white space in debug specifier
137137 t = t "Value: {value = }"
138138 self .assertTStringEqual (
139- t , ("Value: value = " , "" ), [(value , "value" , "r" )]
139+ t , ("Value: value = " , "" ), [(value , "value " , "r" )]
140140 )
141141 self .assertEqual (fstring (t ), "Value: value = 42" )
142142
143+ # Explicit line continuations after the debug marker are part of
144+ # the debug text, not the interpolation expression.
145+ for template , strings , interpolation , rendered in (
146+ (
147+ t """Value: {value =\
148+ }""" ,
149+ ("Value: value =\\ \n " , "" ),
150+ (value , "value " , "r" ),
151+ "Value: value =\\ \n 42" ,
152+ ),
153+ (
154+ t """Value: {value =\
155+ !r}""" ,
156+ ("Value: value =\\ \n " , "" ),
157+ (value , "value " , "r" ),
158+ "Value: value =\\ \n 42" ,
159+ ),
160+ (
161+ t """Value: {value =\
162+ :04}""" ,
163+ ("Value: value =\\ \n " , "" ),
164+ (value , "value " , None , "04" ),
165+ "Value: value =\\ \n 0042" ,
166+ ),
167+ (
168+ t """Value: {value =\
169+ \
170+ }""" ,
171+ ("Value: value =\\ \n \\ \n " , "" ),
172+ (value , "value " , "r" ),
173+ "Value: value =\\ \n \\ \n 42" ,
174+ ),
175+ ):
176+ with self .subTest (template = template ):
177+ self .assertTStringEqual (template , strings , [interpolation ])
178+ self .assertEqual (fstring (template ), rendered )
179+
180+ def test_interpolation_expression_whitespace (self ):
181+ x = 42
182+ for template , expected in (
183+ (t "{x}" , "x" ),
184+ (t "{x }" , "x " ),
185+ (t "{ x}" , " x" ),
186+ (t "{ x }" , " x " ),
187+ (t "{ x }" , " x " ),
188+ (t """{
189+ x
190+ }""" , "\n x\n " ),
191+ (t "{ x !r}" , " x " ),
192+ (t "{ x :.2f}" , " x " ),
193+ (t "{ x = }" , " x " ),
194+ (t "{ x = !r}" , " x " ),
195+ (t "{ x = :.2f}" , " x " ),
196+ (t "{x == 42 = }" , "x == 42 " ),
197+ ):
198+ with self .subTest (template = template ):
199+ self .assertEqual (
200+ template .interpolations [0 ].expression ,
201+ expected ,
202+ )
203+
204+ def test_interpolation_expression_with_reconstructed_metadata (self ):
205+ regular = t '''{(
206+ 1, # Force lexer metadata reconstruction.
207+ "\" #")}'''
208+ debug = t '''{(
209+ 1, # Force lexer metadata reconstruction.
210+ "\" #")=}'''
211+ expected = '(\n 1, \n "\\ "#")'
212+ self .assertEqual (regular .interpolations [0 ].expression , expected )
213+ self .assertEqual (debug .interpolations [0 ].expression , expected )
214+
143215 def test_raw_tstrings (self ):
144216 path = r"C:\Users"
145217 t = rt "{path}\Documents"
0 commit comments