summaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-12-05 21:22:31 +0000
committerMichael Williamson <mike@zwobble.org>2026-12-05 21:22:31 +0000
commitf28a32ae999d35ec5065bbab0ed41364524c0435 (patch)
tree7d555938f8557f0f9a2723d67dae3bc71924eb7b /src/test/java/org/zwobble
parentf7bbf52c8cad3c28fbc75b8628bde3cba8cd0d24 (diff)
Parse params in query definition
Diffstat (limited to 'src/test/java/org/zwobble')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionNodeMatcher.java2
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionParamNodeMatcher.java47
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedParamNodeMatcher.java6
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryDefinitionNodeMatcher.java6
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserFunctionExpressionTests.java10
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserQueryDefinitionTests.java46
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerFunctionExpressionTests.java11
7 files changed, 115 insertions, 13 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionNodeMatcher.java
index 71356e8..1e45982 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionNodeMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionNodeMatcher.java
@@ -30,7 +30,7 @@ public final class UntypedFunctionExpressionNodeMatcher implements org.zwobble.p
return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode.class, this.submatchers);
}
- public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNodeMatcher withParams(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode>> params) {
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNodeMatcher withParams(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode>> params) {
var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode>>(this.submatchers);
submatchers.add(org.zwobble.precisely.Matchers.has("params", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode::params, (org.zwobble.precisely.Matcher) params));
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNodeMatcher(submatchers);
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionParamNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionParamNodeMatcher.java
new file mode 100644
index 0000000..996c590
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionParamNodeMatcher.java
@@ -0,0 +1,47 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.untyped;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher imports
+
+public final class UntypedFunctionExpressionParamNodeMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher isUntypedFunctionExpressionParamNode() {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode>> submatchers;
+
+ private UntypedFunctionExpressionParamNodeMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode>> submatchers
+ ) {
+ this.submatchers = submatchers;
+ }
+
+ public org.zwobble.precisely.MatchResult match(java.lang.Object actual) {
+ return this.toMatcher().match(actual);
+ }
+
+ public org.zwobble.precisely.TextTree describe() {
+ return this.toMatcher().describe();
+ }
+
+ private org.zwobble.precisely.Matcher<java.lang.Object> toMatcher() {
+ return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher withName(org.zwobble.precisely.Matcher<? super String> name) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode::name, (org.zwobble.precisely.Matcher) name));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher withSource(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.sources.Source> source) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("source", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode::source, (org.zwobble.precisely.Matcher) source));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher body
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedParamNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedParamNodeMatcher.java
index c140fb2..f1dcf75 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedParamNodeMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedParamNodeMatcher.java
@@ -36,6 +36,12 @@ public final class UntypedParamNodeMatcher implements org.zwobble.precisely.Matc
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNodeMatcher(submatchers);
}
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNodeMatcher withType(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode> type) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("type", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode::type, (org.zwobble.precisely.Matcher) type));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNodeMatcher(submatchers);
+ }
+
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNodeMatcher withSource(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.sources.Source> source) {
var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode>>(this.submatchers);
submatchers.add(org.zwobble.precisely.Matchers.has("source", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode::source, (org.zwobble.precisely.Matcher) source));
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryDefinitionNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryDefinitionNodeMatcher.java
index adcc2d9..7f1ded1 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryDefinitionNodeMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryDefinitionNodeMatcher.java
@@ -36,6 +36,12 @@ public final class UntypedQueryDefinitionNodeMatcher implements org.zwobble.prec
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNodeMatcher(submatchers);
}
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNodeMatcher withParams(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode>> params) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("params", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode::params, (org.zwobble.precisely.Matcher) params));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNodeMatcher(submatchers);
+ }
+
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNodeMatcher withStatements(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStatementNode>> statements) {
var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode>>(this.submatchers);
submatchers.add(org.zwobble.precisely.Matchers.has("statements", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode::statements, (org.zwobble.precisely.Matcher) statements));
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserFunctionExpressionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserFunctionExpressionTests.java
index 99cf3c0..9813324 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserFunctionExpressionTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserFunctionExpressionTests.java
@@ -3,7 +3,7 @@ package org.zwobble.hobgoblin.compiler.parser;
import org.junit.jupiter.api.Test;
import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNodeMatcher.isUntypedFunctionExpressionNode;
-import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNodeMatcher.isUntypedParamNode;
+import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher.isUntypedFunctionExpressionParamNode;
import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReferenceNodeMatcher.isUntypedReferenceNode;
import static org.zwobble.hobgoblin.compiler.parser.ParserTesting.parseString;
import static org.zwobble.precisely.AssertThat.assertThat;
@@ -31,7 +31,7 @@ public class ParserFunctionExpressionTests {
assertThat(node, isUntypedFunctionExpressionNode()
.withParams(isSequence(
- isUntypedParamNode().withName(equalTo("a"))
+ isUntypedFunctionExpressionParamNode().withName(equalTo("a"))
))
.withBody(isUntypedReferenceNode().withName(equalTo("x")))
);
@@ -44,9 +44,9 @@ public class ParserFunctionExpressionTests {
assertThat(node, isUntypedFunctionExpressionNode()
.withParams(isSequence(
- isUntypedParamNode().withName(equalTo("a")),
- isUntypedParamNode().withName(equalTo("b")),
- isUntypedParamNode().withName(equalTo("c"))
+ isUntypedFunctionExpressionParamNode().withName(equalTo("a")),
+ isUntypedFunctionExpressionParamNode().withName(equalTo("b")),
+ isUntypedFunctionExpressionParamNode().withName(equalTo("c"))
))
.withBody(isUntypedReferenceNode().withName(equalTo("x")))
);
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserQueryDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserQueryDefinitionTests.java
index e5b5a45..255b810 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserQueryDefinitionTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserQueryDefinitionTests.java
@@ -2,9 +2,11 @@ package org.zwobble.hobgoblin.compiler.parser;
import org.junit.jupiter.api.Test;
+import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNodeMatcher.isUntypedParamNode;
import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNodeMatcher.isUntypedQueryDefinitionNode;
import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReferenceNodeMatcher.isUntypedReferenceNode;
import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNodeMatcher.isUntypedReturnNode;
+import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNodeMatcher.isUntypedTypeLevelReferenceNode;
import static org.zwobble.hobgoblin.compiler.parser.ParserTesting.parseString;
import static org.zwobble.precisely.AssertThat.assertThat;
import static org.zwobble.precisely.Matchers.equalTo;
@@ -70,5 +72,49 @@ public class ParserQueryDefinitionTests {
))
);
}
+
+ @Test
+ public void canParseQueryDefinitionWithSingleParam() {
+ var source = """
+ query allAuthors(a: A) {
+ }""";
+
+ var node = parseString(source, Parser::parseNamespaceStatement);
+
+ assertThat(node, isUntypedQueryDefinitionNode()
+ .withName(equalTo("allAuthors"))
+ .withParams(isSequence(
+ isUntypedParamNode()
+ .withName(equalTo("a"))
+ .withType(isUntypedTypeLevelReferenceNode().withName(equalTo("A")))
+ ))
+ .withStatements(isSequence())
+ );
+ }
+
+ @Test
+ public void canParseQueryDefinitionWithMultipleParams() {
+ var source = """
+ query allAuthors(a: A, b: B, c: C) {
+ }""";
+
+ var node = parseString(source, Parser::parseNamespaceStatement);
+
+ assertThat(node, isUntypedQueryDefinitionNode()
+ .withName(equalTo("allAuthors"))
+ .withParams(isSequence(
+ isUntypedParamNode()
+ .withName(equalTo("a"))
+ .withType(isUntypedTypeLevelReferenceNode().withName(equalTo("A"))),
+ isUntypedParamNode()
+ .withName(equalTo("b"))
+ .withType(isUntypedTypeLevelReferenceNode().withName(equalTo("B"))),
+ isUntypedParamNode()
+ .withName(equalTo("c"))
+ .withType(isUntypedTypeLevelReferenceNode().withName(equalTo("C")))
+ ))
+ .withStatements(isSequence())
+ );
+ }
}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerFunctionExpressionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerFunctionExpressionTests.java
index af8005f..6ba102e 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerFunctionExpressionTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerFunctionExpressionTests.java
@@ -1,10 +1,7 @@
package org.zwobble.hobgoblin.compiler.typechecker;
import org.junit.jupiter.api.Test;
-import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode;
-import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode;
-import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode;
-import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReferenceNode;
+import org.zwobble.hobgoblin.compiler.ast.untyped.*;
import org.zwobble.hobgoblin.compiler.builtins.NativeTypes;
import org.zwobble.hobgoblin.compiler.sources.NullSource;
import org.zwobble.hobgoblin.compiler.types.FunctionType;
@@ -49,8 +46,8 @@ public class TypeCheckerFunctionExpressionTests {
@Test
public void paramTypesAreInferredFromHint() {
var untyped = UntypedFunctionExpressionNode.arbitrary()
- .addParam(UntypedParamNode.arbitrary().withName("a"))
- .addParam(UntypedParamNode.arbitrary().withName("b"))
+ .addParam(UntypedFunctionExpressionParamNode.arbitrary().withName("a"))
+ .addParam(UntypedFunctionExpressionParamNode.arbitrary().withName("b"))
.withBody(UntypedNumberLiteralNode.arbitrary().withValue(BigDecimal.ZERO))
.build();
var globalContext = TypeCheckerContextArb.globalContext();
@@ -79,7 +76,7 @@ public class TypeCheckerFunctionExpressionTests {
@Test
public void paramsAreAvailableInFunctionExpressionBody() {
var untyped = UntypedFunctionExpressionNode.arbitrary()
- .addParam(UntypedParamNode.arbitrary().withName("a"))
+ .addParam(UntypedFunctionExpressionParamNode.arbitrary().withName("a"))
.withBody(UntypedReferenceNode.arbitrary().withName("a"))
.build();
var globalContext = TypeCheckerContextArb.globalContext();