package org.shedlang.compiler.shidtopatio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.ast.typed.FreeVariables; import org.shedlang.compiler.shid.ShidNamespace; import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.shid.instructions.ShidDefineFunction; import org.shedlang.compiler.sources.Sources; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; import org.shedlang.compiler.typechecker.TypeInfos; import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.types.NamespaceTypeInfo; import org.shedlang.compiler.types.Types; import java.io.IOException; import java.util.List; import static org.shedlang.compiler.patio.PatioTesting.serializeCompilationUnit; @ExtendWith({SnapshotResolver.class}) public class ShidToPatioNamespaceTests { @Test public void canDefineNamespace(Snapshotter snapshotter) throws IOException { var instruction = new ShidDefineFunction( "f", List.of(), List.of(), FreeVariables.empty(), Shid.block(List.of( Shid.pushUnit(), Shid.return_() )), ShidDefineFunction.Variant.FUNCTION, Sources.NULL ); var instructions = Shid.block(List.of(instruction, Shid.discard())); var namespaceName = NamespaceName.of("An","Example"); var typeInfos = TypeInfos.EMPTY .addNamespaceTypeInfo( namespaceName, NamespaceTypeInfo.builder() .addField("x", Types.INT) .addField("y", Types.STRING) .build() ); var context = ShidToPatioTesting.createContext(typeInfos); var shidNamespace = new ShidNamespace(namespaceName, instructions, Sources.NULL); var result = ShidToPatio.generateNamespace(shidNamespace, context); snapshotter.assertSnapshot(serializeCompilationUnit(result.value())); } }