From 48217d912243feadde179709a61b1741941606f3 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 20 Jul 2023 16:42:22 +0100 Subject: Test PatioCodeGen.generateNamespace() --- .../compiler/patio/PatioCodeGenNamespaceTests.java | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceTests.java (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceTests.java new file mode 100644 index 00000000..a19d3113 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceTests.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.ast.typed.FreeVariables; +import org.shedlang.compiler.sources.Sources; +import org.shedlang.compiler.stackir.instructions.DefineFunctionInstruction; +import org.shedlang.compiler.stackir.instructions.Instruction; +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 java.util.List; + +import static org.shedlang.compiler.patio.PatioTesting.serializeCompilationUnit; + +@ExtendWith({SnapshotResolver.class}) +public class PatioCodeGenNamespaceTests { + @Test + public void canDefineNamespace(Snapshotter snapshotter) throws IOException { + var instruction = new DefineFunctionInstruction( + "f", + List.of(), + List.of(), + FreeVariables.empty(), + List.of( + Instructions.pushUnit(), + Instructions.return_() + ), + Sources.NULL + ); + var instructions = List.of(instruction); + var context = PatioCodeGenContext.EMPTY; + + var result = PatioCodeGen.generateNamespace(instructions, context); + + snapshotter.assertSnapshot(serializeCompilationUnit(result)); + } + +} -- cgit v1.2.3