diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-04-25 10:33:55 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-04-25 10:33:55 +0100 |
| commit | 032cdc6462ad575f62b349152f31e87b187e974d (patch) | |
| tree | 156f6e4170e766016f2de938e4fabe958843bdca /src/test/java | |
| parent | 2a37bf78f778c2955a80f0bbf0ac7d4c14f5c55f (diff) | |
Generate struct type for struct definition
Diffstat (limited to 'src/test/java')
2 files changed, 38 insertions, 1 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerContextArb.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerContextArb.java index 98d8064..b917ba4 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerContextArb.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerContextArb.java @@ -5,6 +5,6 @@ public class TypeCheckerContextArb { } public static TypeCheckerContext context() { - return new TypeCheckerContext(); + return TypeCheckerContext.initial(); } } diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java new file mode 100644 index 0000000..86f78ae --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java @@ -0,0 +1,37 @@ +package org.zwobble.hobgoblin.compiler.typechecker; + +import org.junit.jupiter.api.Test; +import org.zwobble.hobgoblin.compiler.ast.typed.TypedStructDefinitionNode; +import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNode; +import org.zwobble.hobgoblin.compiler.sources.NullSource; +import org.zwobble.hobgoblin.compiler.types.NamespaceName; +import org.zwobble.hobgoblin.compiler.types.StructType; + +import java.util.List; + +import static org.zwobble.precisely.AssertThat.assertThat; +import static org.zwobble.precisely.Matchers.*; + +public class TypeCheckerStructDefinitionTests { + @Test + public void structHasNamespaceFromContext() { + var untyped = new UntypedStructDefinitionNode( + "X", + List.of(), + NullSource.INSTANCE + ); + var context = TypeCheckerContextArb.context(); + context.enterNamespace(NamespaceName.of("a", "b")); + + var typed = TypeChecker.typeCheckNamespaceStatement(untyped, context); + + assertThat(typed, instanceOf( + TypedStructDefinitionNode.class, + has( + "type", + TypedStructDefinitionNode::type, + equalTo(new StructType(NamespaceName.of("a", "b"), "X")) + ) + )); + } +} |
