From 2047794b40b140675ef6f5ae7be83ae4ae603e02 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 23 Sep 2023 16:13:12 +0100 Subject: Add tests for Patio code gen for tuples --- .../patio/PatioCodeGenTupleCreateTests.java | 29 ++++++++++++++++++++++ .../compiler/patio/PatioCodeGenTupleGetTests.java | 27 ++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/patio/PatioCodeGenTupleCreateTests.java create mode 100644 src/test/java/org/shedlang/compiler/patio/PatioCodeGenTupleGetTests.java (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTupleCreateTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTupleCreateTests.java new file mode 100644 index 00000000..b95ca4fb --- /dev/null +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTupleCreateTests.java @@ -0,0 +1,29 @@ +package org.shedlang.compiler.patio; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; +import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.testing.snapshots.SnapshotResolver; +import org.shedlang.compiler.testing.snapshots.Snapshotter; + +import java.io.IOException; + +import static org.shedlang.compiler.patio.PatioTesting.serialize; + +@ExtendWith({SnapshotResolver.class}) +public class PatioCodeGenTupleCreateTests { + @Test + public void canGenerateCodeForTupleCreate(Snapshotter snapshotter) throws IOException { + var stackIr = Instructions.tupleCreate(3); + var context = PatioCodeGenContext.EMPTY + .temporaryPush(new PatioLocalRef("a")) + .temporaryPush(new PatioLocalRef("b")) + .temporaryPush(new PatioLocalRef("c")) + .temporaryPush(new PatioLocalRef("d")); + + var result = PatioCodeGen.generateInstruction(stackIr, context); + + snapshotter.assertSnapshot(serialize(result)); + } +} diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTupleGetTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTupleGetTests.java new file mode 100644 index 00000000..d50b8022 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTupleGetTests.java @@ -0,0 +1,27 @@ +package org.shedlang.compiler.patio; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; +import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.testing.snapshots.SnapshotResolver; +import org.shedlang.compiler.testing.snapshots.Snapshotter; + +import java.io.IOException; + +import static org.shedlang.compiler.patio.PatioTesting.serialize; + +@ExtendWith({SnapshotResolver.class}) +public class PatioCodeGenTupleGetTests { + @Test + public void canGenerateCodeForTupleGet(Snapshotter snapshotter) throws IOException { + var stackIr = Instructions.tupleGet(2); + var context = PatioCodeGenContext.EMPTY + .temporaryPush(new PatioLocalRef("a")) + .temporaryPush(new PatioLocalRef("b")); + + var result = PatioCodeGen.generateInstruction(stackIr, context); + + snapshotter.assertSnapshot(serialize(result)); + } +} -- cgit v1.2.3