summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-10-16 09:03:53 +0100
committerMichael Williamson <mike@zwobble.org>2026-10-16 09:03:53 +0100
commitb0c668a96bc8da225d7a0c35dfd7ce4178ebb7c4 (patch)
tree717467f7c153efec813d7926abd922e9845133f0 /src/test/java
parent77c708cbb7a4fb49db50a8917bdcdd777eff6ccb (diff)
Add SQL AST for CREATE TABLE statements
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriterTests.java58
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlColumnDefinitionMatcher.java47
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlCreateTableStatementMatcher.java47
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlIdentifierMatcher.java41
4 files changed, 193 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriterTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriterTests.java
new file mode 100644
index 0000000..5edf06c
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriterTests.java
@@ -0,0 +1,58 @@
+package org.zwobble.hobgoblin.compiler.output.lang.sql;
+
+import org.junit.jupiter.api.Test;
+import org.zwobble.hobgoblin.compiler.output.CodeWriter;
+import org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnDefinition;
+import org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatement;
+import org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Optional;
+
+import static org.zwobble.precisely.AssertThat.assertThat;
+import static org.zwobble.precisely.Matchers.equalTo;
+
+public class SqlWriterTests {
+ @Test
+ public void createTableStatement() throws IOException {
+ var sql = SqlCreateTableStatement.arbitrary()
+ .withName(id("authors"))
+ .addColumn(SqlColumnDefinition.arbitrary()
+ .withName(id("id"))
+ .withTypeName(id("INT"))
+ )
+ .addColumn(SqlColumnDefinition.arbitrary()
+ .withName(id("name"))
+ .withTypeName(id("TEXT"))
+ )
+ .build();
+
+ var string = write(writer -> writer.writeStatement(sql));
+
+ assertThat(string, equalTo("""
+ CREATE TABLE authors (
+ id INT,
+ name TEXT
+ );"""
+ ));
+ }
+
+ private String write(SqlWriter.Write write) throws IOException {
+ return write(write, Optional.empty());
+ }
+
+ private String write(SqlWriter.Write write, Optional<String> originalContents) throws IOException {
+ var stringWriter = new StringWriter();
+ SqlWriter.writeTo(
+ new CodeWriter.InMemoryCodeWriterFile(originalContents, stringWriter),
+ write
+ );
+ return stringWriter.toString();
+ }
+
+ private SqlIdentifier id(String value) {
+ return new SqlIdentifier(value);
+
+ }
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlColumnDefinitionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlColumnDefinitionMatcher.java
new file mode 100644
index 0000000..cbe2ea9
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlColumnDefinitionMatcher.java
@@ -0,0 +1,47 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.sql.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnDefinitionMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnDefinitionMatcher imports
+
+public final class SqlColumnDefinitionMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnDefinitionMatcher isSqlColumnDefinition() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnDefinitionMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnDefinition>> submatchers;
+
+ private SqlColumnDefinitionMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnDefinition>> 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.output.lang.sql.ast.SqlColumnDefinition.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnDefinitionMatcher withName(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier> name) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnDefinition>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnDefinition::name, (org.zwobble.precisely.Matcher) name));
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnDefinitionMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnDefinitionMatcher withTypeName(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier> typeName) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnDefinition>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("typeName", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnDefinition::typeName, (org.zwobble.precisely.Matcher) typeName));
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnDefinitionMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnDefinitionMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnDefinitionMatcher body
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlCreateTableStatementMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlCreateTableStatementMatcher.java
new file mode 100644
index 0000000..d6c8d57
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlCreateTableStatementMatcher.java
@@ -0,0 +1,47 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.sql.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatementMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatementMatcher imports
+
+public final class SqlCreateTableStatementMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatementMatcher isSqlCreateTableStatement() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatementMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatement>> submatchers;
+
+ private SqlCreateTableStatementMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatement>> 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.output.lang.sql.ast.SqlCreateTableStatement.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatementMatcher withName(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier> name) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatement>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatement::name, (org.zwobble.precisely.Matcher) name));
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatementMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatementMatcher withColumns(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnDefinition>> columns) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatement>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("columns", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatement::columns, (org.zwobble.precisely.Matcher) columns));
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatementMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatementMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatementMatcher body
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlIdentifierMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlIdentifierMatcher.java
new file mode 100644
index 0000000..b96c624
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlIdentifierMatcher.java
@@ -0,0 +1,41 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.sql.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifierMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifierMatcher imports
+
+public final class SqlIdentifierMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifierMatcher isSqlIdentifier() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifierMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier>> submatchers;
+
+ private SqlIdentifierMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier>> 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.output.lang.sql.ast.SqlIdentifier.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifierMatcher withValue(org.zwobble.precisely.Matcher<? super String> value) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("value", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier::value, (org.zwobble.precisely.Matcher) value));
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifierMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifierMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifierMatcher body
+}