summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-04-25 10:33:55 +0100
committerMichael Williamson <mike@zwobble.org>2026-04-25 10:33:55 +0100
commit032cdc6462ad575f62b349152f31e87b187e974d (patch)
tree156f6e4170e766016f2de938e4fabe958843bdca /src/test/java
parent2a37bf78f778c2955a80f0bbf0ac7d4c14f5c55f (diff)
Generate struct type for struct definition
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerContextArb.java2
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java37
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"))
+ )
+ ));
+ }
+}