From fec2b177288643b258fa65bb4b660f080a53e960 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 22 Jul 2023 11:07:53 +0100 Subject: Add Patio code gen for push-string --- .../patio/PatioCodeGenPushStringTests.java | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushStringTests.java (limited to 'src/test/java/org') diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushStringTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushStringTests.java new file mode 100644 index 00000000..28989deb --- /dev/null +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushStringTests.java @@ -0,0 +1,34 @@ +package org.shedlang.compiler.patio; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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 PatioCodeGenPushStringTests { + @Test + public void pushStringIsCompiledToDataAndIndexToData(Snapshotter snapshotter) throws IOException { + var stackIrInstruction = Instructions.pushString("hello"); + var context = PatioCodeGenContext.EMPTY; + + var result = PatioCodeGen.generateInstruction(stackIrInstruction, context); + + snapshotter.assertSnapshot(serialize(result)); + } + + @Test + public void canHaveMultipleStrings(Snapshotter snapshotter) throws IOException { + var context = PatioCodeGenContext.EMPTY; + + var result = PatioCodeGen.generateInstruction(Instructions.pushString("hello"), context); + result = PatioCodeGen.generateInstruction(Instructions.pushString("world"), result); + + snapshotter.assertSnapshot(serialize(result)); + } +} -- cgit v1.2.3