Skip to content

Commit 81e5c50

Browse files
committed
Add test
1 parent 099b2a6 commit 81e5c50

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Lib/test/test_compile.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,19 @@ def continue_in_while():
846846
self.assertEqual(None, opcodes[1].argval)
847847
self.assertEqual('RETURN_VALUE', opcodes[2].opname)
848848

849+
def test_unloop_break_continue(self):
850+
source_template = "with object() as obj:\n {}"
851+
sources = []
852+
for stmt in ('break', 'continue'):
853+
sources.append((stmt, source_template.format(stmt)))
854+
855+
for stmt, source in sources:
856+
with self.subTest(stmt=stmt):
857+
with self.assertRaises(SyntaxError) as err_ctx:
858+
compile(source, f"<unloop_{stmt}>", "exec")
859+
exc = err_ctx.exception
860+
self.assertEqual(exc.lineno, 2)
861+
849862
def test_consts_in_conditionals(self):
850863
def and_true(x):
851864
return True and x

0 commit comments

Comments
 (0)