aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-12-22 20:44:49 +0000
committerMichael Williamson <mike@zwobble.org>2024-12-22 20:44:49 +0000
commit8f0f5c7f448b49652d4a3d6be70b0e867859a6d0 (patch)
treeb07d21c4fa042b6ba5835fbfb1f802622beb01b4 /src/test/java
parent6dd0bb83ea290fcf30f554185d18928e93219180 (diff)
Support any result type for Patio try
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java43
1 files changed, 43 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 e1566c99..f7dcbcb5 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
@@ -791,6 +791,49 @@ public abstract class PatioExampleTests {
}
@Test
+ public void tryCanHaveMultipleResults() throws IOException, InterruptedException {
+ var patioFunction = PatioFunctionDefinition.builder()
+ .withName(FUNCTION_NAME)
+ .withReturnType(PatioTypes.VOID)
+ .addLocal(Patio.val("r1", PatioTypes.INT))
+ .addLocal(Patio.val("r2", PatioTypes.INT))
+ .addLocal(Patio.val("e1", PatioTypes.INT))
+ .addLocal(Patio.val("e2", PatioTypes.INT))
+ .addBodyInstruction(Patio.try_(
+ List.of(Patio.localRef("r1"), Patio.localRef("r2")),
+ List.of(
+ Patio.catchClause(
+ "Error",
+ Patio.localRef("e1"),
+ Patio.block(
+ List.of(),
+ List.of(Patio.intConst(11), Patio.intConst(12))
+ )
+ )
+ ),
+ Patio.block(
+ List.of(),
+ List.of(Patio.intConst(1), Patio.intConst(2))
+ )
+ ))
+ .addBodyInstruction(emitInt(Patio.localRef("r1")))
+ .addBodyInstruction(emitInt(Patio.localRef("r2")))
+ .addBodyInstruction(Patio.returnVoid())
+ .build();
+ var patio = Patio.compilationUnit(List.of(
+ Patio.exceptionTypeDefinition("Error", PatioTypes.INT),
+ patioFunction
+ ));
+
+ var result = run(patio);
+
+ assertThat(result, isSequence(
+ isInt(1),
+ isInt(2)
+ ));
+ }
+
+ @Test
public void vars() throws IOException, InterruptedException {
var patioFunction = PatioFunctionDefinition.builder()
.withName(FUNCTION_NAME)