diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-09-28 14:58:12 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-09-28 14:58:12 +0100 |
| commit | a637fcc83f642d5320608ea7fc20a93f3ec5ab86 (patch) | |
| tree | 7d32340746ba7e053250c5ae8fd24f4f6c990f9e /src/test/java | |
| parent | 81a8685983e718f087319de8f1b27c059bbcf283 (diff) | |
Generate Patio code for defining structs
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineStructTests.java | 33 | ||||
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceTests.java | 15 |
2 files changed, 42 insertions, 6 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineStructTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineStructTests.java new file mode 100644 index 00000000..6d2bd125 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineStructTests.java @@ -0,0 +1,33 @@ +package org.shedlang.compiler.patio; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.types.NamespaceName; +import org.shedlang.compiler.types.Types; + +import java.io.IOException; +import java.util.List; + +import static org.shedlang.compiler.patio.PatioTesting.serialize; + +@ExtendWith({SnapshotResolver.class}) +public class PatioCodeGenDefineStructTests { + @Test + public void canGenerateCodeForDefiineStruct(Snapshotter snapshotter) throws IOException { + var instruction = Instructions.defineStruct( + Types.struct(NamespaceName.of("Example", "Project"), "User"), + List.of( + Instructions.defineStructField("name"), + Instructions.defineStructField("isActive") + ) + ); + var context = PatioCodeGenContext.EMPTY; + + var result = PatioCodeGen.generateInstruction(instruction, context); + + snapshotter.assertSnapshot(serialize(result)); + } +} diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceTests.java index d02c1429..cf9b252f 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceTests.java @@ -39,12 +39,15 @@ public class PatioCodeGenNamespaceTests { ); var instructions = List.<Instruction>of(instruction); var namespaceName = NamespaceName.of("An","Example"); - var context = PatioCodeGenContext.forTypeInfos(new TypeInfos(P.map( - Map.entry(namespaceName, new NamespaceTypeInfo(P.orderedMap( - Map.entry("x", Types.INT), - Map.entry("y", Types.STRING) - ))) - ))); + var context = PatioCodeGenContext.forTypeInfos(new TypeInfos( + P.map( + Map.entry(namespaceName, new NamespaceTypeInfo(P.orderedMap( + Map.entry("x", Types.INT), + Map.entry("y", Types.STRING) + ))) + ), + P.map() + )); var stackIrNamespace = new StackIrNamespace(namespaceName, instructions); var result = PatioCodeGen.generateNamespace(stackIrNamespace, context); |
