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.shid.instructions.Shid; 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 java.io.IOException; import java.util.Optional; import static org.shedlang.compiler.shidtopatio.ShidToPatioTesting.serialize; @ExtendWith({SnapshotResolver.class}) public class ShidToPatioMethodLoadTests { @Test public void canGenerateCodeForMethodLoadInSameNamespace(Snapshotter snapshotter) throws IOException { var namespaceName = NamespaceName.of("Example", "Project"); var structType = Types.struct(namespaceName, "User"); var shidInstruction = Shid.methodLoad(structType, "name"); var typeInfo = TypeCheckerContext.EMPTY.toTypeInfos(); var globalContext = ShidToPatioContext.GlobalContext.forTypeInfos(typeInfo); var context = ShidToPatioContext.initialForCompilationUnit(Optional.of(namespaceName), globalContext) .temporaryPush(new PatioLocalRef("a")); var result = ShidToPatio.generateInstruction(shidInstruction, context); snapshotter.assertSnapshot(serialize(result)); } @Test public void canGenerateCodeForMethodLoadInDifferentNamespace(Snapshotter snapshotter) throws IOException { var namespaceName = NamespaceName.of("Example", "Project"); var otherNamespaceName = NamespaceName.of("Example", "Project2"); var structType = Types.struct(namespaceName, "User"); var shidInstruction = Shid.methodLoad(structType, "name"); var typeInfo = TypeCheckerContext.EMPTY.toTypeInfos(); var globalContext = ShidToPatioContext.GlobalContext.forTypeInfos(typeInfo); var context = ShidToPatioContext.initialForCompilationUnit(Optional.of(otherNamespaceName), globalContext) .temporaryPush(new PatioLocalRef("a")); var result = ShidToPatio.generateInstruction(shidInstruction, context); snapshotter.assertSnapshot(serialize(result)); } }