aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-10-08 11:45:36 +0100
committerMichael Williamson <mike@zwobble.org>2023-10-08 11:45:36 +0100
commit0231ae54d8f0f776424f1b6cb0c8993f34c53c28 (patch)
treeed855ffa18e9beb9bc1133fe000d40406997ba19 /src/test/java
parentcea0bc0d3bfe54a799bbbcd491e3221aa7103aa4 (diff)
Add test for Patio switches
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java47
1 files changed, 47 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 9187ea2c..265dfbde 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
@@ -1,5 +1,6 @@
package org.shedlang.compiler.patio;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.shedlang.compiler.patio.ast.PatioCompilationUnit;
import org.shedlang.compiler.patio.ast.PatioFunctionDefinition;
@@ -48,6 +49,52 @@ public abstract class PatioExampleTests {
}
@Test
+ @Disabled("WIP")
+ public void switch_() throws IOException, InterruptedException {
+ var patioFunction = PatioFunctionDefinition.builder()
+ .withName(FUNCTION_NAME)
+ .withReturnType(PatioTypes.INT)
+ .addLocal(Patio.val("x", PatioTypes.INT))
+ .addLocal(Patio.val("x1", PatioTypes.INT))
+ .addLocal(Patio.val("x2", PatioTypes.INT))
+ .addBodyInstruction(Patio.switch_(
+ List.of(Patio.localRef("x")),
+ Patio.int_(2),
+ List.of(
+ Patio.switchCase(
+ 1,
+ Patio.block(
+ List.of(
+ Patio.localStore(Patio.localRef("x1"), Patio.int_(42))
+ ),
+ List.of(Patio.localRef("x1"))
+ )
+ ),
+ Patio.switchCase(
+ 2,
+ Patio.block(
+ List.of(
+ Patio.localStore(Patio.localRef("x2"), Patio.int_(47))
+ ),
+ List.of(Patio.localRef("x2"))
+ )
+ )
+ ),
+ Patio.block(
+ List.of(Patio.unreachable()),
+ List.of()
+ )
+ ))
+ .addBodyInstruction(Patio.return_(Patio.localRef("x")))
+ .build();
+ var patio = Patio.compilationUnit(List.of(patioFunction));
+
+ var result = run(patio);
+
+ assertThat(result, isSilentExit(47));
+ }
+
+ @Test
public void vars() throws IOException, InterruptedException {
var patioFunction = PatioFunctionDefinition.builder()
.withName(FUNCTION_NAME)