summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ast.py
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2019-12-14 10:24:57 (GMT)
committerPablo Galindo <Pablogsal@gmail.com>2019-12-14 10:24:57 (GMT)
commit5936a4ce914d42af97b9238e5090dedc8d5b0bd2 (patch)
treeca23be7cf3d6180aab701aeb2be24209865ca284 /Lib/test/test_ast.py
parent95826c773a9004fc5b3c89de55f800504685ab21 (diff)
downloadcpython-5936a4ce914d42af97b9238e5090dedc8d5b0bd2.zip
cpython-5936a4ce914d42af97b9238e5090dedc8d5b0bd2.tar.gz
cpython-5936a4ce914d42af97b9238e5090dedc8d5b0bd2.tar.bz2
Fix elif start column offset when there is an else following (GH-17596)
Diffstat (limited to 'Lib/test/test_ast.py')
-rw-r--r--Lib/test/test_ast.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index 955bc0d..cd35f96 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -70,6 +70,8 @@ exec_tests = [
"if v:pass",
# If-Elif
"if a:\n pass\nelif b:\n pass",
+ # If-Elif-Else
+ "if a:\n pass\nelif b:\n pass\nelse:\n pass",
# With
"with x as y: pass",
"with x as y, z as q: pass",
@@ -869,6 +871,12 @@ Module(
self.assertEqual(elif_stmt.lineno, 3)
self.assertEqual(elif_stmt.col_offset, 0)
+ def test_elif_stmt_start_position_with_else(self):
+ node = ast.parse('if a:\n pass\nelif b:\n pass\nelse:\n pass\n')
+ elif_stmt = node.body[0].orelse[0]
+ self.assertEqual(elif_stmt.lineno, 3)
+ self.assertEqual(elif_stmt.col_offset, 0)
+
def test_literal_eval(self):
self.assertEqual(ast.literal_eval('[1, 2, 3]'), [1, 2, 3])
self.assertEqual(ast.literal_eval('{"foo": 42}'), {"foo": 42})
@@ -1852,6 +1860,7 @@ exec_results = [
('Module', [('While', (1, 0), ('Name', (1, 6), 'v', ('Load',)), [('Pass', (1, 8))], [])], []),
('Module', [('If', (1, 0), ('Name', (1, 3), 'v', ('Load',)), [('Pass', (1, 5))], [])], []),
('Module', [('If', (1, 0), ('Name', (1, 3), 'a', ('Load',)), [('Pass', (2, 2))], [('If', (3, 0), ('Name', (3, 5), 'b', ('Load',)), [('Pass', (4, 2))], [])])], []),
+('Module', [('If', (1, 0), ('Name', (1, 3), 'a', ('Load',)), [('Pass', (2, 2))], [('If', (3, 0), ('Name', (3, 5), 'b', ('Load',)), [('Pass', (4, 2))], [('Pass', (6, 2))])])], []),
('Module', [('With', (1, 0), [('withitem', ('Name', (1, 5), 'x', ('Load',)), ('Name', (1, 10), 'y', ('Store',)))], [('Pass', (1, 13))], None)], []),
('Module', [('With', (1, 0), [('withitem', ('Name', (1, 5), 'x', ('Load',)), ('Name', (1, 10), 'y', ('Store',))), ('withitem', ('Name', (1, 13), 'z', ('Load',)), ('Name', (1, 18), 'q', ('Store',)))], [('Pass', (1, 21))], None)], []),
('Module', [('Raise', (1, 0), ('Call', (1, 6), ('Name', (1, 6), 'Exception', ('Load',)), [('Constant', (1, 16), 'string', None)], []), None)], []),