File tree Expand file tree Collapse file tree 2 files changed +19
-12
lines changed
Expand file tree Collapse file tree 2 files changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -880,6 +880,25 @@ def f():
880880 for src in srcs :
881881 ast .parse (src )
882882
883+ def test_tstring (self ):
884+ # Test AST structure for simple t-string
885+ tree = ast .parse ('t"Hello"' )
886+ self .assertIsInstance (tree .body [0 ].value , ast .TemplateStr )
887+ self .assertIsInstance (tree .body [0 ].value .values [0 ], ast .Constant )
888+
889+ # Test AST for t-string with interpolation
890+ tree = ast .parse ('t"Hello {name}"' )
891+ self .assertIsInstance (tree .body [0 ].value , ast .TemplateStr )
892+ self .assertIsInstance (tree .body [0 ].value .values [0 ], ast .Constant )
893+ self .assertIsInstance (tree .body [0 ].value .values [1 ], ast .Interpolation )
894+
895+ # Test AST for implicit concat of t-string with f-string
896+ tree = ast .parse ('t"Hello {name}" f"{name}"' )
897+ self .assertIsInstance (tree .body [0 ].value , ast .TemplateStr )
898+ self .assertIsInstance (tree .body [0 ].value .values [0 ], ast .Constant )
899+ self .assertIsInstance (tree .body [0 ].value .values [1 ], ast .Interpolation )
900+ self .assertIsInstance (tree .body [0 ].value .values [2 ], ast .FormattedValue )
901+
883902
884903class CopyTests (unittest .TestCase ):
885904 """Test copying and pickling AST nodes."""
Original file line number Diff line number Diff line change @@ -202,18 +202,6 @@ def test_nested_templates(self):
202202 self .assertEqual (t_interp .conversion , None )
203203 self .assertEqual (t_interp .format_spec , "" )
204204
205- def test_ast_structure (self ):
206- # Test AST structure for simple t-string
207- tree = ast .parse ('t"Hello"' )
208- self .assertIsInstance (tree .body [0 ].value , ast .TemplateStr )
209- self .assertIsInstance (tree .body [0 ].value .values [0 ], ast .Constant )
210-
211- # Test AST for t-string with interpolation
212- tree = ast .parse ('t"Hello {name}"' )
213- self .assertIsInstance (tree .body [0 ].value , ast .TemplateStr )
214- self .assertIsInstance (tree .body [0 ].value .values [0 ], ast .Constant )
215- self .assertIsInstance (tree .body [0 ].value .values [1 ], ast .Interpolation )
216-
217205 def test_syntax_errors (self ):
218206 for case , err in (
219207 ("t'" , "unterminated t-string literal" ),
You can’t perform that action at this time.
0 commit comments