diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-09-23 16:13:12 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-09-23 16:13:12 +0100 |
| commit | 2047794b40b140675ef6f5ae7be83ae4ae603e02 (patch) | |
| tree | 112e58990d143dc78cc742e00a48fd3c0939fb4b /src/test/java | |
| parent | 22b8e0b0b04f1320b76804c34785b97081d378c7 (diff) | |
Add tests for Patio code gen for tuples
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioCodeGenTupleCreateTests.java | 29 | ||||
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioCodeGenTupleGetTests.java | 27 |
2 files changed, 56 insertions, 0 deletions
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)); + } +} |
