From 609443828eee69163b5524666c6cf281849cec70 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 26 Nov 2023 19:00:08 +0000 Subject: Test multiple catch clauses in try --- .../backends/llvm/LlvmPatioCodeGenTests.java | 6 +++ .../shedlang/compiler/patio/PatioExampleTests.java | 51 ++++++++++++++++++++++ 2 files changed, 57 insertions(+) (limited to 'src/test/java') 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 @@ -281,6 +281,57 @@ public abstract class PatioExampleTests { assertThat(result, isSilentExit(2)); } + @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() -- cgit v1.2.3