diff --git a/tests/basics/bytes.py b/tests/basics/bytes.py index 0b6b14fa55bb..ba14c26da8de 100644 --- a/tests/basics/bytes.py +++ b/tests/basics/bytes.py @@ -2,7 +2,6 @@ print(b'123') print(br'123') print(rb'123') -print(b'\u1234') # construction print(bytes()) diff --git a/tests/basics/bytes_escape_unicode.py b/tests/basics/bytes_escape_unicode.py new file mode 100644 index 000000000000..1e450696f4f4 --- /dev/null +++ b/tests/basics/bytes_escape_unicode.py @@ -0,0 +1,3 @@ +# Coverage test for unicode escape in a bytes literal. +# CPython issues a SyntaxWarning for this. +print(b"\u1234") diff --git a/tests/basics/bytes_escape_unicode.py.exp b/tests/basics/bytes_escape_unicode.py.exp new file mode 100644 index 000000000000..6affe51896eb --- /dev/null +++ b/tests/basics/bytes_escape_unicode.py.exp @@ -0,0 +1 @@ +b'\\u1234' diff --git a/tests/basics/string1.py b/tests/basics/string1.py index b3abfb9c608b..ca8dfd5399a5 100644 --- a/tests/basics/string1.py +++ b/tests/basics/string1.py @@ -5,7 +5,6 @@ print(r'abc') print(u'abc') print(repr('\a\b\t\n\v\f\r')) -print('\z') # unrecognised escape char # construction print(str()) diff --git a/tests/basics/string_escape_invalid.py b/tests/basics/string_escape_invalid.py new file mode 100644 index 000000000000..d9fdd6e54658 --- /dev/null +++ b/tests/basics/string_escape_invalid.py @@ -0,0 +1,4 @@ +# Test invalid escape characters. +# CPython issues a SyntaxWarning for this. + +print("\z") diff --git a/tests/basics/string_escape_invalid.py.exp b/tests/basics/string_escape_invalid.py.exp new file mode 100644 index 000000000000..c642929c6e84 --- /dev/null +++ b/tests/basics/string_escape_invalid.py.exp @@ -0,0 +1 @@ +\z diff --git a/tests/basics/string_fstring.py b/tests/basics/string_fstring.py index 1a3960680e4f..42d093b37b50 100644 --- a/tests/basics/string_fstring.py +++ b/tests/basics/string_fstring.py @@ -29,21 +29,6 @@ def foo(a, b): # Nested '{' and '}' characters. print(f"a{ {0,1,2}}") -# PEP-0498 specifies that '\\' and '#' must be disallowed explicitly, whereas -# MicroPython relies on the syntax error as a result of the substitution. - -print(f"\\") -print(f'#') -try: - eval("f'{\}'") -except SyntaxError: - print('SyntaxError') -try: - eval("f'{#}'") -except SyntaxError: - print('SyntaxError') - - # PEP-0498 specifies that handling of double braces '{{' or '}}' should # behave like str.format. print(f'{{}}') diff --git a/tests/basics/string_fstring_invalid.py b/tests/basics/string_fstring_invalid.py new file mode 100644 index 000000000000..6fce323c5bce --- /dev/null +++ b/tests/basics/string_fstring_invalid.py @@ -0,0 +1,13 @@ +# PEP-0498 specifies that '\\' and '#' must be disallowed explicitly, whereas +# MicroPython relies on the syntax error as a result of the substitution. + +print(f"\\") +print(f"#") +try: + eval("f'{\}'") +except SyntaxError: + print("SyntaxError") +try: + eval("f'{#}'") +except SyntaxError: + print("SyntaxError") diff --git a/tests/basics/string_fstring_invalid.py.exp b/tests/basics/string_fstring_invalid.py.exp new file mode 100644 index 000000000000..bcb7f259e556 --- /dev/null +++ b/tests/basics/string_fstring_invalid.py.exp @@ -0,0 +1,4 @@ +\ +# +SyntaxError +SyntaxError