summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-10-31 10:38:04 +0000
committerMichael Williamson <mike@zwobble.org>2026-10-31 10:38:34 +0000
commitda5f2e83708371b1497665c7d0ee8f382898247c (patch)
treef21f27e34278b2bdae61f3bbc49775e80f63c3c1 /src/test/java
parent6efdb8a8aaa87d5497de989b4f8e4ee26d2bdd54 (diff)
Evaluate reference in query body
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedQueryDefinitionNodeMatcher.java6
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerQueryDefinitionTests.java31
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))
);
}
}