diff options
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioCodeGenFieldLoadTests.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenFieldLoadTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenFieldLoadTests.java new file mode 100644 index 00000000..f4bb5152 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenFieldLoadTests.java @@ -0,0 +1,41 @@ +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 org.shedlang.compiler.typechecker.TypeCheckerContext; +import org.shedlang.compiler.types.NamespaceName; +import org.shedlang.compiler.types.Types; +import org.shedlang.compiler.util.P; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import static org.shedlang.compiler.patio.PatioTesting.serialize; + +@ExtendWith({SnapshotResolver.class}) +public class PatioCodeGenFieldLoadTests { + @Test + public void canGenerateCodeForFieldLoad(Snapshotter snapshotter) throws IOException { + var namespaceName = new NamespaceName(List.of("Example", "Project")); + var stackIrInstruction = Instructions.fieldLoad(namespaceName, "y"); + var typeInfo = TypeCheckerContext.EMPTY + .addNamespaceFields(namespaceName, P.orderedMap( + Map.entry("x", Types.INT), + Map.entry("y", Types.INT), + Map.entry("z", Types.INT) + )) + .toTypeInfo(); + var context = PatioCodeGenContext.forTypeInfo(typeInfo) + .temporaryPush(new PatioLocalRef("a")) + .temporaryPush(new PatioLocalRef("b")); + + var result = PatioCodeGen.generateInstruction(stackIrInstruction, context); + + snapshotter.assertSnapshot(serialize(result)); + } +} |
