aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-11-26 19:00:08 +0000
committerMichael Williamson <mike@zwobble.org>2023-11-26 19:00:08 +0000
commit609443828eee69163b5524666c6cf281849cec70 (patch)
treec59bf2d4cba71ed662fa66d4fd530e264464fc0d /src/test/java
parentdcd48e7774260e0b21e63393d92b24e053905408 (diff)
Test multiple catch clauses in try
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGenTests.java6
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java51
2 files changed, 57 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGenTests.java b/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGenTests.java
index 27543828..a1af75c4 100644
--- a/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGenTests.java
+++ b/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioCodeGenTests.java
@@ -84,4 +84,10 @@ public class LlvmPatioCodeGenTests extends PatioExampleTests {
public void catchClauseCanThrow() {
}
+
+ @Disabled("WIP")
+ @Test
+ public void multipleCatchClausesCanBeAttachedToSameTry() {
+
+ }
}
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
index dc61101d..3d590111 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
@@ -282,6 +282,57 @@ public abstract class PatioExampleTests {
}
@Test
+ public void multipleCatchClausesCanBeAttachedToSameTry() throws IOException, InterruptedException {
+ var patioFunction = PatioFunctionDefinition.builder()
+ .withName(FUNCTION_NAME)
+ .withReturnType(PatioTypes.INT)
+ .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")),
+ List.of(
+ Patio.catchClause(
+ "Error1",
+ Patio.localRef("e2"),
+ Patio.block(
+ List.of(),
+ List.of(Patio.int_(1))
+ )
+ ),
+ Patio.catchClause(
+ "Error2",
+ Patio.localRef("e2"),
+ Patio.block(
+ List.of(),
+ List.of(Patio.int_(2))
+ )
+ )
+ ),
+ Patio.block(
+ List.of(
+ Patio.throw_("Error2", Patio.int_(0))
+ ),
+ List.of(Patio.int_(0))
+ )
+ ))
+ .addBodyInstruction(Patio.return_(
+ Patio.localRef("r1")
+ ))
+ .build();
+ var patio = Patio.compilationUnit(List.of(
+ Patio.exceptionTypeDefinition("Error1", PatioTypes.INT),
+ Patio.exceptionTypeDefinition("Error2", PatioTypes.INT),
+ patioFunction
+ ));
+
+ var result = run(patio);
+
+ assertThat(result, isSilentExit(2));
+ }
+
+ @Test
public void whenExceptionIsThrownThenExceptionHandlerForOtherExceptionsIsIgnored() throws IOException, InterruptedException {
var patioFunction = PatioFunctionDefinition.builder()
.withName(FUNCTION_NAME)