diff options
Diffstat (limited to 'src/test/java')
2 files changed, 15 insertions, 22 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedQueryDefinitionNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedQueryDefinitionNodeMatcher.java index bf3272d..651ede0 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedQueryDefinitionNodeMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedQueryDefinitionNodeMatcher.java @@ -36,6 +36,12 @@ public final class TypedQueryDefinitionNodeMatcher implements org.zwobble.precis return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNodeMatcher(submatchers); } + public org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNodeMatcher withTable(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.types.Table> table) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("table", org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode::table, (org.zwobble.precisely.Matcher) table)); + return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNodeMatcher(submatchers); + } + public org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNodeMatcher withDocComment(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.DocComment> docComment) { var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode>>(this.submatchers); submatchers.add(org.zwobble.precisely.Matchers.has("docComment", org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode::docComment, (org.zwobble.precisely.Matcher) docComment)); diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerQueryDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerQueryDefinitionTests.java index 84b3e25..4ecc1c6 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerQueryDefinitionTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerQueryDefinitionTests.java @@ -1,20 +1,17 @@ package org.zwobble.hobgoblin.compiler.typechecker; import org.junit.jupiter.api.Test; -import org.zwobble.hobgoblin.compiler.ast.untyped.*; -import org.zwobble.hobgoblin.compiler.builtins.NativeTypes; +import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode; +import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReferenceNode; +import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNode; +import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode; import org.zwobble.hobgoblin.compiler.sources.NullSource; import org.zwobble.hobgoblin.compiler.types.*; -import org.zwobble.hobgoblin.compiler.util.SequencedMaps; - -import java.util.List; -import java.util.Map; -import java.util.Optional; import static org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNodeMatcher.isTypedQueryDefinitionNode; import static org.zwobble.hobgoblin.compiler.typechecker.TypeCheckerTesting.typeCheckNamespaceStatement; import static org.zwobble.precisely.AssertThat.assertThat; -import static org.zwobble.precisely.Matchers.*; +import static org.zwobble.precisely.Matchers.equalTo; public class TypeCheckerQueryDefinitionTests { @Test @@ -23,31 +20,21 @@ public class TypeCheckerQueryDefinitionTests { .withName("allAuthors") .withDatabaseSchema(UntypedTypeLevelReferenceNode.arbitrary().withName("blogApp")) .addStatement(UntypedReturnNode.arbitrary().withExpression( - UntypedMemberAccessNode.arbitrary() - .withReceiver(UntypedReferenceNode.arbitrary().withName("blogApp")) - .withFieldName("authors") + UntypedReferenceNode.arbitrary().withName("authors") )) .build(); var globalContext = TypeCheckerContextArb.globalContext(); var namespaceName = NamespaceName.of("App"); var namespaceContext = globalContext.enterNamespace(namespaceName); - var authorType = new SimpleStructType(namespaceName, "Author"); - namespaceContext.declare("Author", Types.metaType(authorType), NullSource.INSTANCE); - var authorIdField = new Field("id", NativeTypes.INT_32, NullSource.INSTANCE); - namespaceContext.defineStructType(authorType, Optional.of(List.of( - authorIdField - ))); var databaseSchema = new DatabaseSchema(namespaceName, "blogApp"); - namespaceContext.defineDatabaseSchema(databaseSchema, new DatabaseSchemaInfo( - SequencedMaps.ofEntries( - Map.entry("authors", new TableInfo(authorType, authorIdField)) - ) - )); + var table = new Table(databaseSchema, "authors"); + namespaceContext.declare("authors", Types.table(table), NullSource.INSTANCE); var typed = typeCheckNamespaceStatement(untyped, namespaceContext); assertThat(typed, isTypedQueryDefinitionNode() .withName(equalTo("allAuthors")) + .withTable(equalTo(table)) ); } } |
