diff options
Diffstat (limited to 'src/test/java/org')
4 files changed, 30 insertions, 11 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerNamespaceTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerNamespaceTests.java index 82cccf3..1c19daf 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerNamespaceTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerNamespaceTests.java @@ -4,12 +4,14 @@ import org.junit.jupiter.api.Test; import org.zwobble.hobgoblin.compiler.ast.typed.TypedNamespaceNode; import org.zwobble.hobgoblin.compiler.ast.typed.TypedStructDefinitionNode; import org.zwobble.hobgoblin.compiler.ast.untyped.*; +import org.zwobble.hobgoblin.compiler.sources.NullSource; import org.zwobble.hobgoblin.compiler.types.*; import java.util.List; import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.zwobble.hobgoblin.compiler.types.TypeMatchers.isField; import static org.zwobble.hobgoblin.compiler.types.TypeMatchers.isMetaType; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.*; @@ -73,8 +75,11 @@ public class TypeCheckerNamespaceTests { .build(); var context = TypeCheckerContextArb.globalContext(); context.defineNamespace(NamespaceName.of("a", "c"), List.of( - new Field("Y", new TypeLevelValueType(new SimpleNativeType(NamespaceName.of("a", "c"), "Y")) - ))); + new Field( + "Y", + new TypeLevelValueType(new SimpleNativeType(NamespaceName.of("a", "c"), "Y")), + NullSource.INSTANCE + ))); var typed = TypeChecker.typeCheckNamespace(untyped, context); @@ -94,7 +99,7 @@ public class TypeCheckerNamespaceTests { assertThat( context.toTypesInfo().fieldsOf(new StructType(NamespaceName.of("a", "b"), "X")), isSequence( - equalTo(new Field("y", new SimpleNativeType(NamespaceName.of("a", "c"), "Y"))) + isField("y", new SimpleNativeType(NamespaceName.of("a", "c"), "Y")) ) ); } 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 81bf9b8..0efe3b4 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java @@ -5,13 +5,18 @@ import org.zwobble.hobgoblin.compiler.ast.typed.TypedNamespaceNode; 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.*; -import org.zwobble.hobgoblin.compiler.types.*; +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.types.NamespaceName; +import org.zwobble.hobgoblin.compiler.types.SimpleNativeType; +import org.zwobble.hobgoblin.compiler.types.StructType; import java.util.List; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.zwobble.hobgoblin.compiler.typechecker.TypeCheckerTesting.typeCheckNamespaceStatement; +import static org.zwobble.hobgoblin.compiler.types.TypeMatchers.isField; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.*; @@ -83,8 +88,8 @@ public class TypeCheckerStructDefinitionTests { assertThat( typesInfo.fieldsOf(new StructType(namespaceName, "X")), isSequence( - equalTo(new Field("a", int32Type)), - equalTo(new Field("b", int64Type)) + isField("a", int32Type), + isField("b", int64Type) ) ); } diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSumDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSumDefinitionTests.java index c19ee7f..597fb42 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSumDefinitionTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSumDefinitionTests.java @@ -6,6 +6,7 @@ import org.zwobble.hobgoblin.compiler.ast.typed.TypedSumDefinitionNode; import org.zwobble.hobgoblin.compiler.ast.typed.TypedSumVariantDefinitionNode; import org.zwobble.hobgoblin.compiler.ast.typed.TypedTypeLevelExpressionNode; import org.zwobble.hobgoblin.compiler.ast.untyped.*; +import org.zwobble.hobgoblin.compiler.sources.NullSource; import org.zwobble.hobgoblin.compiler.types.*; import java.util.List; @@ -193,7 +194,7 @@ public class TypeCheckerSumDefinitionTests { .enterNamespace(namespaceName); var variantType = new StructType(namespaceName, "Square"); namespaceContext.declare("Square", new TypeLevelValueType(variantType)); - namespaceContext.defineStructType(variantType, List.of(new Field("area", int64Type))); + namespaceContext.defineStructType(variantType, List.of(new Field("area", int64Type, NullSource.INSTANCE))); // TODO: more specific error var error = assertThrows( @@ -254,7 +255,7 @@ public class TypeCheckerSumDefinitionTests { namespaceContext.defineSumType( sumType, List.of(variantType), - List.of(new Field("area", int32Type)) + List.of(new Field("area", int32Type, NullSource.INSTANCE)) ); assertThrows( diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/types/TypeMatchers.java b/src/test/java/org/zwobble/hobgoblin/compiler/types/TypeMatchers.java index d676d89..42d5d4e 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/types/TypeMatchers.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/types/TypeMatchers.java @@ -2,7 +2,8 @@ package org.zwobble.hobgoblin.compiler.types; import org.zwobble.precisely.Matcher; -import static org.zwobble.precisely.Matchers.equalTo; +import static org.zwobble.precisely.Matchers.*; +import static org.zwobble.precisely.Matchers.has; public class TypeMatchers { private TypeMatchers() {} @@ -10,4 +11,11 @@ public class TypeMatchers { public static Matcher<Type> isMetaType(Type type) { return equalTo(new TypeLevelValueType(type)); } + + public static Matcher<Field> isField(String name, Type type) { + return allOf( + has("name", Field::name, equalTo(name)), + has("type", Field::type, equalTo(type)) + ); + } } |
