aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_grammar.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_grammar.py')
-rw-r--r--Lib/test/test_grammar.py41
1 files changed, 40 insertions, 1 deletions
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index 35cd6984267..7f5d48b9c63 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -1,7 +1,7 @@
# Python test set -- part 1, grammar.
# This just tests whether the parser accepts them all.
-from test.support import check_syntax_error
+from test.support import check_syntax_error, skip_wasi_stack_overflow
from test.support import import_helper
import annotationlib
import inspect
@@ -216,6 +216,27 @@ the \'lazy\' dog.\n\
'
self.assertEqual(x, y)
+ def test_string_prefixes(self):
+ def check(s):
+ parsed = eval(s)
+ self.assertIs(type(parsed), str)
+ self.assertGreater(len(parsed), 0)
+
+ check("u'abc'")
+ check("r'abc\t'")
+ check("rf'abc\a {1 + 1}'")
+ check("fr'abc\a {1 + 1}'")
+
+ def test_bytes_prefixes(self):
+ def check(s):
+ parsed = eval(s)
+ self.assertIs(type(parsed), bytes)
+ self.assertGreater(len(parsed), 0)
+
+ check("b'abc'")
+ check("br'abc\t'")
+ check("rb'abc\a'")
+
def test_ellipsis(self):
x = ...
self.assertTrue(x is Ellipsis)
@@ -228,6 +249,18 @@ the \'lazy\' dog.\n\
compile(s, "<test>", "exec")
self.assertIn("was never closed", str(cm.exception))
+ @skip_wasi_stack_overflow()
+ def test_max_level(self):
+ # Macro defined in Parser/lexer/state.h
+ MAXLEVEL = 200
+
+ result = eval("(" * MAXLEVEL + ")" * MAXLEVEL)
+ self.assertEqual(result, ())
+
+ with self.assertRaises(SyntaxError) as cm:
+ eval("(" * (MAXLEVEL + 1) + ")" * (MAXLEVEL + 1))
+ self.assertStartsWith(str(cm.exception), 'too many nested parentheses')
+
var_annot_global: int # a global annotated is necessary for test_var_annot
@@ -1507,6 +1540,8 @@ class GrammarTests(unittest.TestCase):
check('[None (3, 4)]')
check('[True (3, 4)]')
check('[... (3, 4)]')
+ check('[t"{x}" (3, 4)]')
+ check('[t"x={x}" (3, 4)]')
msg=r'is not subscriptable; perhaps you missed a comma\?'
check('[{1, 2} [i, j]]')
@@ -1529,6 +1564,8 @@ class GrammarTests(unittest.TestCase):
check('[f"x={x}" [i, j]]')
check('["abc" [i, j]]')
check('[b"abc" [i, j]]')
+ check('[t"{x}" [i, j]]')
+ check('[t"x={x}" [i, j]]')
msg=r'indices must be integers or slices, not tuple;'
check('[[1, 2] [3, 4]]')
@@ -1549,6 +1586,8 @@ class GrammarTests(unittest.TestCase):
check('[[1, 2] [f"{x}"]]')
check('[[1, 2] [f"x={x}"]]')
check('[[1, 2] ["abc"]]')
+ check('[[1, 2] [t"{x}"]]')
+ check('[[1, 2] [t"x={x}"]]')
msg=r'indices must be integers or slices, not'
check('[[1, 2] [b"abc"]]')
check('[[1, 2] [12.3]]')