aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_ast.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_ast.py')
-rw-r--r--Lib/test/test_ast.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index 68249583996..80d24e94040 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -1,6 +1,7 @@
import ast
import builtins
import dis
+import enum
import os
import sys
import types
@@ -698,6 +699,35 @@ class AST_Tests(unittest.TestCase):
with self.assertRaisesRegex(ValueError, f"Name node can't be used with '{constant}' constant"):
compile(expr, "<test>", "eval")
+ def test_precedence_enum(self):
+ class _Precedence(enum.IntEnum):
+ """Precedence table that originated from python grammar."""
+ TUPLE = enum.auto()
+ YIELD = enum.auto() # 'yield', 'yield from'
+ TEST = enum.auto() # 'if'-'else', 'lambda'
+ OR = enum.auto() # 'or'
+ AND = enum.auto() # 'and'
+ NOT = enum.auto() # 'not'
+ CMP = enum.auto() # '<', '>', '==', '>=', '<=', '!=',
+ # 'in', 'not in', 'is', 'is not'
+ EXPR = enum.auto()
+ BOR = EXPR # '|'
+ BXOR = enum.auto() # '^'
+ BAND = enum.auto() # '&'
+ SHIFT = enum.auto() # '<<', '>>'
+ ARITH = enum.auto() # '+', '-'
+ TERM = enum.auto() # '*', '@', '/', '%', '//'
+ FACTOR = enum.auto() # unary '+', '-', '~'
+ POWER = enum.auto() # '**'
+ AWAIT = enum.auto() # 'await'
+ ATOM = enum.auto()
+ def next(self):
+ try:
+ return self.__class__(self + 1)
+ except ValueError:
+ return self
+ enum._test_simple_enum(_Precedence, ast._Precedence)
+
class ASTHelpers_Test(unittest.TestCase):
maxDiff = None