From 9cbc19c49933411cdd7e57e7c5de9a04314a387c Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 11 Oct 2026 20:08:25 +0100 Subject: Specify row type for tables --- .../ast/untyped/UntypedTableDefinitionNodeMatcher.java | 6 ++++++ .../compiler/parser/ParserDatabaseSchemaDefinitionTests.java | 10 ++++++---- .../hobgoblin/compiler/parser/ParserTableDefinitionTests.java | 9 +++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'src/test/java') 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 index 4c016a3..8e4226c 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTableDefinitionNodeMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTableDefinitionNodeMatcher.java @@ -36,6 +36,12 @@ public final class UntypedTableDefinitionNodeMatcher implements org.zwobble.prec return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher(submatchers); } + public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher withRowType(org.zwobble.precisely.Matcher rowType) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("rowType", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode::rowType, (org.zwobble.precisely.Matcher) rowType)); + return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher(submatchers); + } + public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher withDocComment(org.zwobble.precisely.Matcher docComment) { var submatchers = new java.util.ArrayList>(this.submatchers); submatchers.add(org.zwobble.precisely.Matchers.has("docComment", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode::docComment, (org.zwobble.precisely.Matcher) docComment)); 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 8241eda..5c41fa1 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserDatabaseSchemaDefinitionTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserDatabaseSchemaDefinitionTests.java @@ -31,10 +31,12 @@ public class ParserDatabaseSchemaDefinitionTests { public void schemaWithStatements() { var source = """ databaseSchema BlogApp { - table Post { + table posts { + row Post; } - table Author { + table author { + row Author; } }"""; @@ -46,8 +48,8 @@ public class ParserDatabaseSchemaDefinitionTests { assertThat(node, isUntypedDatabaseSchemaDefinitionNode() .withName(equalTo("BlogApp")) .withBody(isSequence( - isUntypedTableDefinitionNode().withName(equalTo("Post")), - isUntypedTableDefinitionNode().withName(equalTo("Author")) + isUntypedTableDefinitionNode().withName(equalTo("posts")), + 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 index b39d203..889b30c 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserTableDefinitionTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserTableDefinitionTests.java @@ -3,6 +3,7 @@ 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.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; @@ -11,7 +12,8 @@ public class ParserTableDefinitionTests { @Test public void minimalTable() { var source = """ - table Post { + table posts { + row Post; }"""; var node = parseString( @@ -19,6 +21,9 @@ public class ParserTableDefinitionTests { Parser::parseDatabaseSchemaStatement ); - assertThat(node, isUntypedTableDefinitionNode().withName(equalTo("Post"))); + assertThat(node, isUntypedTableDefinitionNode() + .withName(equalTo("posts")) + .withRowType(isUntypedTypeLevelReferenceNode().withName(equalTo("Post"))) + ); } } -- cgit v1.2.3