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.java66
1 files changed, 27 insertions, 39 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 873f5ac..f45b215 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java
@@ -1,7 +1,6 @@
package org.zwobble.hobgoblin.compiler.typechecker;
import org.junit.jupiter.api.Test;
-import org.zwobble.hobgoblin.compiler.ast.DocComment;
import org.zwobble.hobgoblin.compiler.ast.typed.TypedNamespaceNode;
import org.zwobble.hobgoblin.compiler.ast.typed.TypedStructDefinitionNode;
import org.zwobble.hobgoblin.compiler.ast.typed.TypedStructFieldDefinitionNode;
@@ -10,7 +9,6 @@ import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedArb;
import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNamespaceNode;
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.Field;
import org.zwobble.hobgoblin.compiler.types.NamespaceName;
import org.zwobble.hobgoblin.compiler.types.SimpleNativeType;
@@ -25,12 +23,9 @@ import static org.zwobble.precisely.Matchers.*;
public class TypeCheckerStructDefinitionTests {
@Test
public void structHasNamespaceFromContext() {
- var untyped = new UntypedStructDefinitionNode(
- "X",
- List.of(),
- DocComment.EMPTY,
- NullSource.INSTANCE
- );
+ var untyped = UntypedStructDefinitionNode.arbitrary()
+ .withName("X")
+ .build();
var context = TypeCheckerContextArb.namespaceContext(NamespaceName.of("a", "b"));
var typed = typeCheckNamespaceStatement(untyped, context);
@@ -49,15 +44,13 @@ public class TypeCheckerStructDefinitionTests {
public void fieldsAreTypeChecked() {
var int32Type = SimpleNativeType.builtin("Int32");
var int64Type = SimpleNativeType.builtin("Int64");
- var untyped = new UntypedStructDefinitionNode(
- "X",
- List.of(
- new UntypedStructFieldDefinitionNode("a", UntypedArb.typeLevelReference("Int32"), NullSource.INSTANCE),
- new UntypedStructFieldDefinitionNode("b", UntypedArb.typeLevelReference("Int64"), NullSource.INSTANCE)
- ),
- DocComment.EMPTY,
- NullSource.INSTANCE
- );
+ var untyped = UntypedStructDefinitionNode.arbitrary()
+ .withName("X")
+ .withFields(List.of(
+ UntypedStructFieldDefinitionNode.arbitrary().withName("a").withType(UntypedArb.typeLevelReference("Int32")).build(),
+ UntypedStructFieldDefinitionNode.arbitrary().withName("b").withType(UntypedArb.typeLevelReference("Int64")).build()
+ ))
+ .build();
var globalContext = TypeCheckerGlobalContext.initial();
globalContext.addNativeType(int32Type);
globalContext.addNativeType(int64Type);
@@ -105,28 +98,23 @@ public class TypeCheckerStructDefinitionTests {
public void structCanUseTypeDefinedLater() {
var int32Type = SimpleNativeType.builtin("Int32");
var namespaceName = NamespaceName.of("a", "b");
- var untyped = new UntypedNamespaceNode(
- namespaceName,
- List.of(
- new UntypedStructDefinitionNode(
- "X",
- List.of(
- new UntypedStructFieldDefinitionNode("value", UntypedArb.typeLevelReference("Y"), NullSource.INSTANCE)
- ),
- DocComment.EMPTY,
- NullSource.INSTANCE
- ),
- new UntypedStructDefinitionNode(
- "Y",
- List.of(
- new UntypedStructFieldDefinitionNode("value", UntypedArb.typeLevelReference("Int32"), NullSource.INSTANCE)
- ),
- DocComment.EMPTY,
- NullSource.INSTANCE
- )
- ),
- NullSource.INSTANCE
- );
+ var untyped = UntypedNamespaceNode.arbitrary()
+ .withNamespaceName(namespaceName)
+ .withBody(List.of(
+ UntypedStructDefinitionNode.arbitrary()
+ .withName("X")
+ .withFields(List.of(
+ UntypedStructFieldDefinitionNode.arbitrary().withName("value").withType(UntypedArb.typeLevelReference("Y")).build()
+ ))
+ .build(),
+ UntypedStructDefinitionNode.arbitrary()
+ .withName("Y")
+ .withFields(List.of(
+ UntypedStructFieldDefinitionNode.arbitrary().withName("value").withType(UntypedArb.typeLevelReference("Int32")).build()
+ ))
+ .build()
+ ))
+ .build();
var context = TypeCheckerContextArb.globalContext();
context.addNativeType(int32Type);