diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-05-29 16:52:15 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-05-29 16:52:15 +0100 |
| commit | 5117960fbc14ee7275fc6ee1193f9ee5e5c78554 (patch) | |
| tree | 9830ca252af4ac60f00144c7653209725a043589 /src | |
| parent | 4aba8acb545d4523346ba618488825dc17b9dfff (diff) | |
Use builder in TypeCheckerStructDefinitionTests
Diffstat (limited to 'src')
5 files changed, 31 insertions, 43 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedConstructedTypeNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedConstructedTypeNode.java index c9ca4e4..6a74b8a 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedConstructedTypeNode.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedConstructedTypeNode.java @@ -2,7 +2,7 @@ package org.zwobble.hobgoblin.compiler.ast.untyped; public record UntypedConstructedTypeNode(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode receiver, java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode> args, org.zwobble.hobgoblin.compiler.sources.Source source) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode { public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedConstructedTypeNode.Builder arbitrary() { - return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedConstructedTypeNode.Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedConstructedTypeNode.arbitrary().build(), java.util.List.of(), org.zwobble.hobgoblin.compiler.ast.untyped.Native.arbitrarySource()); + return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedConstructedTypeNode.Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode.arbitrary().build(), java.util.List.of(), org.zwobble.hobgoblin.compiler.ast.untyped.Native.arbitrarySource()); } public record Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode receiver, java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode> args, org.zwobble.hobgoblin.compiler.sources.Source source) { diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedStructFieldDefinitionNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedStructFieldDefinitionNode.java index ba34624..77af253 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedStructFieldDefinitionNode.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedStructFieldDefinitionNode.java @@ -2,7 +2,7 @@ package org.zwobble.hobgoblin.compiler.ast.untyped; public record UntypedStructFieldDefinitionNode(String name, org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode type, org.zwobble.hobgoblin.compiler.sources.Source source) { public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructFieldDefinitionNode.Builder arbitrary() { - return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructFieldDefinitionNode.Builder("", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedConstructedTypeNode.arbitrary().build(), org.zwobble.hobgoblin.compiler.ast.untyped.Native.arbitrarySource()); + return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructFieldDefinitionNode.Builder("", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode.arbitrary().build(), org.zwobble.hobgoblin.compiler.ast.untyped.Native.arbitrarySource()); } public record Builder(String name, org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode type, org.zwobble.hobgoblin.compiler.sources.Source source) { diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedSumVariantDefinitionNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedSumVariantDefinitionNode.java index daba7ce..ba7012c 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedSumVariantDefinitionNode.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedSumVariantDefinitionNode.java @@ -2,7 +2,7 @@ package org.zwobble.hobgoblin.compiler.ast.untyped; public record UntypedSumVariantDefinitionNode(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode type, org.zwobble.hobgoblin.compiler.sources.Source source) { public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode.Builder arbitrary() { - return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode.Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedConstructedTypeNode.arbitrary().build(), org.zwobble.hobgoblin.compiler.ast.untyped.Native.arbitrarySource()); + return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedSumVariantDefinitionNode.Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode.arbitrary().build(), org.zwobble.hobgoblin.compiler.ast.untyped.Native.arbitrarySource()); } public record Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode type, org.zwobble.hobgoblin.compiler.sources.Source source) { diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTypeLevelExpressionNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTypeLevelExpressionNode.java index 956afb7..3884c1f 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTypeLevelExpressionNode.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTypeLevelExpressionNode.java @@ -1,6 +1,6 @@ package org.zwobble.hobgoblin.compiler.ast.untyped; -public sealed interface UntypedTypeLevelExpressionNode permits org.zwobble.hobgoblin.compiler.ast.untyped.UntypedConstructedTypeNode, org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode { +public sealed interface UntypedTypeLevelExpressionNode permits org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode, org.zwobble.hobgoblin.compiler.ast.untyped.UntypedConstructedTypeNode { // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode body // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode body } 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); |
