diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-05-25 14:18:55 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-25 14:18:55 +0300 |
commit | 89a310264000a613b7f6abd5916946aef09ae7d2 (patch) | |
tree | ec44bf0f4208d8eb69633861c5c415a40a802084 /Lib/test/test_fstring.py | |
parent | a2a9984a278d2ee945e91ce13e000e571794fc24 (diff) | |
download | cpython-git-89a310264000a613b7f6abd5916946aef09ae7d2.tar.gz |
[3.6] bpo-29104: Fixed parsing backslashes in f-strings. (GH-490) (#1812)
(cherry picked from commit 0cd7a3f)
Diffstat (limited to 'Lib/test/test_fstring.py')
-rw-r--r-- | Lib/test/test_fstring.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py index 708ed25b52..25730029ae 100644 --- a/Lib/test/test_fstring.py +++ b/Lib/test/test_fstring.py @@ -361,6 +361,20 @@ f'{a * x()}'""" self.assertEqual(f'2\x203', '2 3') self.assertEqual(f'\x203', ' 3') + with self.assertWarns(DeprecationWarning): # invalid escape sequence + value = eval(r"f'\{6*7}'") + self.assertEqual(value, '\\42') + self.assertEqual(f'\\{6*7}', '\\42') + self.assertEqual(fr'\{6*7}', '\\42') + + AMPERSAND = 'spam' + # Get the right unicode character (&), or pick up local variable + # depending on the number of backslashes. + self.assertEqual(f'\N{AMPERSAND}', '&') + self.assertEqual(f'\\N{AMPERSAND}', '\\Nspam') + self.assertEqual(fr'\N{AMPERSAND}', '\\Nspam') + self.assertEqual(f'\\\N{AMPERSAND}', '\\&') + def test_misformed_unicode_character_name(self): # These test are needed because unicode names are parsed # differently inside f-strings. |