summaryrefslogtreecommitdiffstats
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.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index 03d9b31..896eb5b 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -335,6 +335,33 @@ class AST_Tests(unittest.TestCase):
for snippet in snippets_to_validate:
tree = ast.parse(snippet)
compile(tree, '<string>', 'exec')
+
+ def test_invalid_position_information(self):
+ invalid_linenos = [
+ (10, 1), (-10, -11), (10, -11), (-5, -2), (-5, 1)
+ ]
+
+ for lineno, end_lineno in invalid_linenos:
+ with self.subTest(f"Check invalid linenos {lineno}:{end_lineno}"):
+ snippet = "a = 1"
+ tree = ast.parse(snippet)
+ tree.body[0].lineno = lineno
+ tree.body[0].end_lineno = end_lineno
+ with self.assertRaises(ValueError):
+ compile(tree, '<string>', 'exec')
+
+ invalid_col_offsets = [
+ (10, 1), (-10, -11), (10, -11), (-5, -2), (-5, 1)
+ ]
+ for col_offset, end_col_offset in invalid_col_offsets:
+ with self.subTest(f"Check invalid col_offset {col_offset}:{end_col_offset}"):
+ snippet = "a = 1"
+ tree = ast.parse(snippet)
+ tree.body[0].col_offset = col_offset
+ tree.body[0].end_col_offset = end_col_offset
+ with self.assertRaises(ValueError):
+ compile(tree, '<string>', 'exec')
+
def test_slice(self):
slc = ast.parse("x[::]").body[0].value.slice