diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-04-06 15:05:58 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-04-06 15:05:58 +0100 |
| commit | 0afa2b177ed80ad94704f5c1f536c1177033bd84 (patch) | |
| tree | 7d258d6024a5294de6a8bd289ee31c15cd071f4d | |
| parent | 9331d0f454a30091628d2fa1c26e805626917d0a (diff) | |
Add test for Patio loop
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java | 35 |
1 files changed, 35 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 4d24fd5e..0fa702ec 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -390,6 +390,41 @@ public abstract class PatioExampleTests { } @Test + public void loopRunsUntilEndIsReachedWithoutContinue() throws IOException, InterruptedException { + var patioFunction = PatioFunctionDefinition.builder() + .withName(FUNCTION_NAME) + .withReturnType(PatioTypes.VOID) + .addLocal(Patio.val("c", PatioTypes.BOOL)) + .addLocal(Patio.var("x_var", PatioTypes.INT)) + .addLocal(Patio.val("x_current", PatioTypes.INT)) + .addLocal(Patio.val("x_next", PatioTypes.INT)) + .addBodyInstruction(Patio.varStore(Patio.localRef("x_var"), Patio.intConst(3))) + .addBodyInstruction(Patio.loop(List.of( + Patio.varLoad(Patio.localRef("x_current"), Patio.localRef("x_var")), + emitInt(Patio.localRef("x_current")), + Patio.intAdd(Patio.localRef("x_next"), Patio.localRef("x_current"), Patio.intConst(-1)), + Patio.varStore(Patio.localRef("x_var"), Patio.localRef("x_next")), + Patio.intEquals(Patio.localRef("c"), Patio.localRef("x_next"), Patio.intConst(1)), + Patio.if_( + List.of(), + Patio.localRef("c"), + Patio.block(List.of(), List.of()), + Patio.block(List.of(Patio.loopContinue()), List.of()) + ) + ))) + .addBodyInstruction(Patio.returnVoid()) + .build(); + var patio = Patio.compilationUnit(List.of(patioFunction)); + + var result = run(patio); + + assertThat(result, isSequence( + isInt(3), + isInt(2) + )); + } + + @Test public void boolToIntToBoolIsIdentityForFalse() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() .withName(FUNCTION_NAME) |
