diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2022-10-18 16:18:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-18 16:18:38 (GMT) |
commit | c051d55ddb29c4ff7b1fcc65971535f78369ffc0 (patch) | |
tree | 256633e998ca1083f244d3d0ce5ff3c74aae3b4c /Lib/test | |
parent | debacd9ad51eaeedac5517404de5ead3f2258c22 (diff) | |
download | cpython-c051d55ddb29c4ff7b1fcc65971535f78369ffc0.zip cpython-c051d55ddb29c4ff7b1fcc65971535f78369ffc0.tar.gz cpython-c051d55ddb29c4ff7b1fcc65971535f78369ffc0.tar.bz2 |
gh-98390: Fix source locations of boolean sub-expressions (GH-98396)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_compile.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index f5c0c76..a5434d6 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -1207,6 +1207,32 @@ f( self.assertOpcodeSourcePositionIs(compiled_code, 'CALL', line=1, end_line=3, column=0, end_column=1) + def test_multiline_boolean_expression(self): + snippet = """\ +if (a or + (b and not c) or + not ( + d > 0)): + x = 42 +""" + + compiled_code, _ = self.check_positions_against_ast(snippet) + # jump if a is true: + self.assertOpcodeSourcePositionIs(compiled_code, 'POP_JUMP_IF_TRUE', + line=1, end_line=1, column=4, end_column=5, occurrence=1) + # jump if b is false: + self.assertOpcodeSourcePositionIs(compiled_code, 'POP_JUMP_IF_FALSE', + line=2, end_line=2, column=5, end_column=6, occurrence=1) + # jump if c is false: + self.assertOpcodeSourcePositionIs(compiled_code, 'POP_JUMP_IF_FALSE', + line=2, end_line=2, column=15, end_column=16, occurrence=2) + # compare d and 0 + self.assertOpcodeSourcePositionIs(compiled_code, 'COMPARE_OP', + line=4, end_line=4, column=8, end_column=13, occurrence=1) + # jump if comparison it True + self.assertOpcodeSourcePositionIs(compiled_code, 'POP_JUMP_IF_TRUE', + line=4, end_line=4, column=8, end_column=13, occurrence=2) + def test_very_long_line_end_offset(self): # Make sure we get the correct column offset for offsets # too large to store in a byte. |