summaryrefslogtreecommitdiff
path: root/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java
index b6fddba..f13731f 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java
@@ -2,10 +2,16 @@ 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.typed.TypedStructFieldDefinitionNode;
+import org.zwobble.hobgoblin.compiler.ast.typed.TypedTypeLevelExpressionNode;
+import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedArb;
import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNode;
+import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructFieldDefinitionNode;
import org.zwobble.hobgoblin.compiler.sources.NullSource;
import org.zwobble.hobgoblin.compiler.types.NamespaceName;
+import org.zwobble.hobgoblin.compiler.types.ScalarType;
import org.zwobble.hobgoblin.compiler.types.StructType;
+import org.zwobble.hobgoblin.compiler.types.TypeLevelValueType;
import java.util.List;
@@ -33,4 +39,51 @@ public class TypeCheckerStructDefinitionTests {
)
));
}
+
+ @Test
+ public void fieldsAreTypeChecked() {
+ var int32Type = new ScalarType("Int32");
+ var int64Type = new ScalarType("Int64");
+ var untyped = new UntypedStructDefinitionNode(
+ "X",
+ List.of(
+ new UntypedStructFieldDefinitionNode("a", UntypedArb.typeLevelReference("Int32"), NullSource.INSTANCE),
+ new UntypedStructFieldDefinitionNode("b", UntypedArb.typeLevelReference("Int64"), NullSource.INSTANCE)
+ ),
+ NullSource.INSTANCE
+ );
+ var context = TypeCheckerContextArb.namespaceContext(NamespaceName.of("a", "b"));
+ context.declare(int32Type.name());
+ context.define(int32Type.name(), new TypeLevelValueType(int32Type));
+ context.declare(int64Type.name());
+ context.define(int64Type.name(), new TypeLevelValueType(int64Type));
+
+ var typed = TypeChecker.typeCheckNamespaceStatement(untyped, context);
+
+ assertThat(typed, instanceOf(
+ TypedStructDefinitionNode.class,
+ has(
+ "fields",
+ TypedStructDefinitionNode::fields,
+ isSequence(
+ allOf(
+ has("name", TypedStructFieldDefinitionNode::name, equalTo("a")),
+ has("type", TypedStructFieldDefinitionNode::type, has(
+ "value",
+ TypedTypeLevelExpressionNode::value,
+ equalTo(int32Type)
+ ))
+ ),
+ allOf(
+ has("name", TypedStructFieldDefinitionNode::name, equalTo("b")),
+ has("type", TypedStructFieldDefinitionNode::type, has(
+ "value",
+ TypedTypeLevelExpressionNode::value,
+ equalTo(int64Type)
+ ))
+ )
+ )
+ )
+ ));
+ }
}