package org.shedlang.compiler.shidtopatio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.operands.PatioLocalRef; import org.shedlang.compiler.patio.types.PatioTypes; import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; import java.io.IOException; import static org.shedlang.compiler.shidtopatio.ShidToPatioTesting.serialize; @ExtendWith({SnapshotResolver.class}) public class ShidToPatioVarStoreTests { @Test public void canGenerateCodeForVarStore(Snapshotter snapshotter) throws IOException { var shid = Shid.varStore("x"); var context = ShidToPatioContext.EMPTY .declareShidVal("x", PatioTypes.DATA_PTR).context() .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")); var result = ShidToPatio.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } @Test public void canStoreIntoVarMultipleTimes(Snapshotter snapshotter) throws IOException { var shid = Shid.varStore("x"); var context = ShidToPatioContext.EMPTY .declareShidVal("x", PatioTypes.DATA_PTR).context() .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")); var result = ShidToPatio.generateInstruction(shid, context); result = ShidToPatio.generateInstruction(shid, result); snapshotter.assertSnapshot(serialize(result)); } }