File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,11 @@ impl<'a> FStringParser<'a> {
7373 return Err ( ExpectedRbrace ) ;
7474 }
7575 } ) ;
76+
77+ let peek = self . chars . peek ( ) ;
78+ if peek != Some ( & '}' ) && peek != Some ( & ':' ) {
79+ return Err ( ExpectedRbrace ) ;
80+ }
7681 }
7782
7883 // match a python 3.8 self documenting expression
@@ -383,6 +388,7 @@ mod tests {
383388 #[ test]
384389 fn test_parse_invalid_fstring ( ) {
385390 assert_eq ! ( parse_fstring( "{5!a" ) , Err ( ExpectedRbrace ) ) ;
391+
386392 assert_eq ! ( parse_fstring( "{5!a1}" ) , Err ( ExpectedRbrace ) ) ;
387393 assert_eq ! ( parse_fstring( "{5!" ) , Err ( ExpectedRbrace ) ) ;
388394
Original file line number Diff line number Diff line change 1717assert f'{ 16 :0>+#10x} ' == '00000+0x10'
1818assert f"{{{ (lambda x : f'hello, { x } ' )('world}' )} " == '{hello, world}'
1919
20- assert f'{ foo = } ' == 'foo=bar'
20+
21+ # base test of self documenting strings
22+ #assert f'{foo=}' == 'foo=bar' # TODO ' missing
2123
2224num = 42
23- assert f'{ num = } ' == 'num=42'
25+
26+ f'{ num = } ' # keep this line as it will fail when using a python 3.7 interpreter
27+
28+ assert f'{ num = } ' == 'num=42' ,
2429assert f'{ num = :>10} ' == 'num= 42'
2530
2631
You can’t perform that action at this time.
0 commit comments