Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,30 @@ public void testSteppingAsExpected() throws Throwable {
}
}

@Test
public void testSteppingMultipleStatementsOnSameLine() throws Throwable {
final Source source = Source.newBuilder("python", "a = 1; b = 2; a + b", "test_same_line.py").buildLiteral();

try (DebuggerSession session = tester.startSession()) {
session.suspendNextExecution();
tester.startEval(source);

expectSuspended((SuspendedEvent event) -> {
assertEquals("a = 1", event.getSourceSection().getCharacters().toString());
event.prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
assertEquals("b = 2", event.getSourceSection().getCharacters().toString());
event.prepareStepOver(1);
});
expectSuspended((SuspendedEvent event) -> {
assertEquals("a + b", event.getSourceSection().getCharacters().toString());
event.prepareContinue();
});
assertEquals("3", tester.expectDone());
}
}

@Test
public void testException() throws Throwable {
final Source source = Source.newBuilder("python", "" +
Expand Down
41 changes: 41 additions & 0 deletions graalpython/com.oracle.graal.python.test/src/tests/test_patmat.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,47 @@ def alternatives(value):
assert alternatives({"x": 43}) == 43


def test_ast_transformed_class_pattern_bindings():
source = """
def match_int(value):
match value:
case int(real=x):
assert x == 42
case _:
return False
return True
"""
tree = ast.parse(source)
case = tree.body[0].body[0].cases[0]
original_assert = case.body[0]

# Mimic assertion rewriting: replace one source statement with several AST statements that
# share its source range. This used to make the class-pattern capture's StackValue escape the
# source-section operation in which it was created.
case.body = [
ast.copy_location(
ast.Assign(targets=[ast.Name(id="assert_result", ctx=ast.Store())], value=original_assert.test),
original_assert,
),
ast.copy_location(
ast.If(
test=ast.UnaryOp(op=ast.Not(), operand=ast.Name(id="assert_result", ctx=ast.Load())),
body=[
ast.Raise(
exc=ast.Call(func=ast.Name(id="AssertionError", ctx=ast.Load()), args=[], keywords=[])
)
],
orelse=[],
),
original_assert,
),
]
ast.fix_missing_locations(tree)

namespace = {}
exec(compile(tree, "<rewritten-assert>", "exec"), namespace)
assert namespace["match_int"](42)


class TestErrors(unittest.TestCase):
def assert_syntax_error(self, code: str):
Expand Down
Loading
Loading