diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-04-05 22:36:06 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-04-05 22:36:06 +0100 |
| commit | c7964e6b2ef1682989488756888ad399f1127034 (patch) | |
| tree | eb8311146a770f2fe406e4b58a9e683c4dd65faa /src/test/java | |
| parent | 6fc24f5205f2419f10a1729a749b4335332ecf79 (diff) | |
Add test for calling local patio function
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java index 8a2cea87..c55cd1f1 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -644,6 +644,35 @@ public abstract class PatioExampleTests { } @Test + public void canCallFunctionDefinedInModule() throws IOException, InterruptedException { + var calledFunction = PatioFunctionDefinition.builder() + .withName("get") + .withReturnType(PatioTypes.INT) + .addBodyInstruction(Patio.return_(Patio.intConst(42))) + .build(); + + var patioFunction = PatioFunctionDefinition.builder() + .withName(FUNCTION_NAME) + .withReturnType(PatioTypes.VOID) + .addLocal(Patio.val("x", PatioTypes.INT)) + .addBodyInstruction(Patio.call( + Optional.of(Patio.localRef("x")), + calledFunction.name(), + List.of() + )) + .addBodyInstruction(emitInt(Patio.localRef("x"))) + .addBodyInstruction(Patio.returnVoid()) + .build(); + var patio = Patio.compilationUnit(List.of(calledFunction, patioFunction)); + + var result = run(patio); + + assertThat(result, isSequence( + isInt(42) + )); + } + + @Test public void whenExceptionIsNotThrownThenTryReturnsFromBody() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) |
