From db4001cc5a801626d4c25274eb63b7c3e23a858c Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 3 Apr 2026 10:16:07 +0100 Subject: Add Patio tests for int-equals --- .../shedlang/compiler/patio/PatioExampleTests.java | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java index 25219c9e..838b4606 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -365,6 +365,53 @@ public abstract class PatioExampleTests { )); } + @Test + public void intEquals() throws IOException, InterruptedException { + assertIntEquals(42, 47, 0); + assertIntEquals(42, 42, 1); + } + + private void assertIntEquals( + int left, + int right, + int expected + ) throws IOException, InterruptedException { + var patioFunction = PatioFunctionDefinition.builder() + .withName(FUNCTION_NAME) + .withReturnType(PatioTypes.VOID) + .addLocal(Patio.val("x", PatioTypes.INT)) + .addLocal(Patio.val("y", PatioTypes.INT)) + .addLocal(Patio.val("z_bool", PatioTypes.BOOL)) + .addLocal(Patio.val("z_int", PatioTypes.INT)) + .addBodyInstruction(Patio.localStore( + Patio.localRef("x"), + Patio.intConst(left) + )) + .addBodyInstruction(Patio.localStore( + Patio.localRef("y"), + Patio.intConst(right) + )) + .addBodyInstruction(Patio.intEquals( + Patio.localRef("z_bool"), + Patio.localRef("x"), + Patio.localRef("y") + )) + .addBodyInstruction(Patio.boolToInt( + Patio.localRef("z_int"), + Patio.localRef("z_bool") + )) + .addBodyInstruction(emitInt(Patio.localRef("z_int"))) + .addBodyInstruction(Patio.returnVoid()) + .build(); + var patio = Patio.compilationUnit(List.of(patioFunction)); + + var result = run(patio); + + assertThat(result, isSequence( + isInt(expected) + )); + } + @Test public void intSub() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() -- cgit v1.2.3