From db12d15e0813805a22ae8345628fe411f7127b0e Mon Sep 17 00:00:00 2001 From: Aralox Date: Wed, 21 Oct 2020 10:38:58 +1100 Subject: [PATCH] Fix token_dump for strings with single quotes in them. Update f-string test tokens. --- scripts/token_dump | 1 + tests/tokenized/f-string.txt | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/token_dump b/scripts/token_dump index 1207055..41bbcb3 100755 --- a/scripts/token_dump +++ b/scripts/token_dump @@ -145,6 +145,7 @@ def string_token(line, n_line, pysrc): while True: end = line.find(quotes, start) if end > 0 and line[end - 1] == '\\': + content += line[start:end + 1] start = end + 1 continue elif end >= 0: diff --git a/tests/tokenized/f-string.txt b/tests/tokenized/f-string.txt index d4cf784..07ac59b 100644 --- a/tests/tokenized/f-string.txt +++ b/tests/tokenized/f-string.txt @@ -21,10 +21,10 @@ print ( f'{123}:\\s+' ) print ( f'x{12}' * 3 ) print ( f'f-string. \t\tformat value 0: {var1}, 1 (!s): {var2!s}, 2 (!r): {var2!r}, 3 (!a): {var2!a}, 4: {var3:6.3}, constant: {123}. End.' ) print ( 'percent format %d ' % 444 + f'f-string {123} and {var1!s}' + f' add another f-str {var3:2.3}' + ' regular string regular string ' ) -print ( f'' ) +print ( f'\'\'\'{\'single quoted string\'} \'singles in f-string\' {"single quote \' inside"} "doubles in f-string" {\'double quoted string\'} " both \' {\'double quotes " inside\'}\'\'\'' ) print ( f'"""{\'single quoted string\'} \'singles in f-string\' {"single quote \' inside"} "doubles in f-string" {\'double quoted string\'} " both \' {\'double quotes " inside\'}"""' ) -print ( f'' ) -print ( f'' ) +print ( f'single quote \t\t{var1}"{var1!s}" \'{var2!a}{var3:.2f}\' """{var1!r}""" \'\'\'{var2}\'\'\'' ) +print ( f'double quote \t\t{var1}"{var1!s}" \'{var2!a}{var3:.2f}\' """{var1!r}""" \'\'\'{var2}\'\'\'' ) print ( f'{var3 * x} {var3:.2f} {var3:.5f} {x:02} {x * x:3} {x * x * x:4} {s1:>10} {a:x} {a:o} {a:e}' ) print ( f'some {{braces}} {\'inner literal: {braces} {{double braces}}\'}' ) print ( f'f-string dict {some_dict[2]} and {{function call in expression}}: {max([\n 1,\n 20,\n 3])}' )