summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-10-10 11:40:25 +0100
committerMichael Williamson <mike@zwobble.org>2026-10-10 11:40:25 +0100
commit864c5b173a72e269fa6f009c51326c78a042d260 (patch)
treee525485fc4b67459dc8d4e30aa9691f2127eb48c /src/test/java
parent78e75def13c9a0890f6a3880a95184fedc7ee13d (diff)
Parse empty table definition
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedDatabaseSchemaDefinitionNodeMatcher.java6
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTableDefinitionNodeMatcher.java53
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserDatabaseSchemaDefinitionTests.java31
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserTableDefinitionTests.java24
4 files changed, 112 insertions, 2 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedDatabaseSchemaDefinitionNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedDatabaseSchemaDefinitionNodeMatcher.java
index cb132e0..1654ed6 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedDatabaseSchemaDefinitionNodeMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedDatabaseSchemaDefinitionNodeMatcher.java
@@ -36,6 +36,12 @@ public final class UntypedDatabaseSchemaDefinitionNodeMatcher implements org.zwo
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedDatabaseSchemaDefinitionNodeMatcher(submatchers);
}
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedDatabaseSchemaDefinitionNodeMatcher withBody(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedDatabaseSchemaStatementNode>> body) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedDatabaseSchemaDefinitionNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("body", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedDatabaseSchemaDefinitionNode::body, (org.zwobble.precisely.Matcher) body));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedDatabaseSchemaDefinitionNodeMatcher(submatchers);
+ }
+
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedDatabaseSchemaDefinitionNodeMatcher 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.untyped.UntypedDatabaseSchemaDefinitionNode>>(this.submatchers);
submatchers.add(org.zwobble.precisely.Matchers.has("docComment", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedDatabaseSchemaDefinitionNode::docComment, (org.zwobble.precisely.Matcher) docComment));
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTableDefinitionNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTableDefinitionNodeMatcher.java
new file mode 100644
index 0000000..4c016a3
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTableDefinitionNodeMatcher.java
@@ -0,0 +1,53 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.untyped;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher imports
+
+public final class UntypedTableDefinitionNodeMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher isUntypedTableDefinitionNode() {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode>> submatchers;
+
+ private UntypedTableDefinitionNodeMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode>> 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.UntypedTableDefinitionNode.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher 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.UntypedTableDefinitionNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode::name, (org.zwobble.precisely.Matcher) name));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher 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.untyped.UntypedTableDefinitionNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("docComment", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode::docComment, (org.zwobble.precisely.Matcher) docComment));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher 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.UntypedTableDefinitionNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("source", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode::source, (org.zwobble.precisely.Matcher) source));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher body
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserDatabaseSchemaDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserDatabaseSchemaDefinitionTests.java
index a43d616..8241eda 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserDatabaseSchemaDefinitionTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserDatabaseSchemaDefinitionTests.java
@@ -1,12 +1,13 @@
package org.zwobble.hobgoblin.compiler.parser;
import org.junit.jupiter.api.Test;
-import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNode;
import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedDatabaseSchemaDefinitionNodeMatcher.isUntypedDatabaseSchemaDefinitionNode;
+import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher.isUntypedTableDefinitionNode;
import static org.zwobble.hobgoblin.compiler.parser.ParserTesting.parseString;
import static org.zwobble.precisely.AssertThat.assertThat;
-import static org.zwobble.precisely.Matchers.*;
+import static org.zwobble.precisely.Matchers.equalTo;
+import static org.zwobble.precisely.Matchers.isSequence;
public class ParserDatabaseSchemaDefinitionTests {
@Test
@@ -22,6 +23,32 @@ public class ParserDatabaseSchemaDefinitionTests {
assertThat(node, isUntypedDatabaseSchemaDefinitionNode()
.withName(equalTo("BlogApp"))
+ .withBody(isSequence())
+ );
+ }
+
+ @Test
+ public void schemaWithStatements() {
+ var source = """
+ databaseSchema BlogApp {
+ table Post {
+ }
+
+ table Author {
+ }
+ }""";
+
+ var node = parseString(
+ source,
+ Parser::parseNamespaceStatement
+ );
+
+ assertThat(node, isUntypedDatabaseSchemaDefinitionNode()
+ .withName(equalTo("BlogApp"))
+ .withBody(isSequence(
+ isUntypedTableDefinitionNode().withName(equalTo("Post")),
+ isUntypedTableDefinitionNode().withName(equalTo("Author"))
+ ))
);
}
}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserTableDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserTableDefinitionTests.java
new file mode 100644
index 0000000..b39d203
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserTableDefinitionTests.java
@@ -0,0 +1,24 @@
+package org.zwobble.hobgoblin.compiler.parser;
+
+import org.junit.jupiter.api.Test;
+
+import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher.isUntypedTableDefinitionNode;
+import static org.zwobble.hobgoblin.compiler.parser.ParserTesting.parseString;
+import static org.zwobble.precisely.AssertThat.assertThat;
+import static org.zwobble.precisely.Matchers.equalTo;
+
+public class ParserTableDefinitionTests {
+ @Test
+ public void minimalTable() {
+ var source = """
+ table Post {
+ }""";
+
+ var node = parseString(
+ source,
+ Parser::parseDatabaseSchemaStatement
+ );
+
+ assertThat(node, isUntypedTableDefinitionNode().withName(equalTo("Post")));
+ }
+}