From 2a5290cb52b6d95f9461e4bcdfffc4c56c573361 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 5 Dec 2026 20:16:19 +0000 Subject: Add column reference to SQL AST --- .../compiler/output/lang/sql/SqlWriterTests.java | 12 ++++++ .../lang/sql/ast/SqlColumnReferenceMatcher.java | 47 ++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlColumnReferenceMatcher.java (limited to 'src/test/java/org/zwobble') 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 index 4f9771a..2a96c4b 100644 --- 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 @@ -214,6 +214,18 @@ public class SqlWriterTests { assertThat(string, equalTo("42 == 47")); } + @Test + public void columnReference() throws IOException { + var sql = SqlColumnReference.arbitrary() + .withRelationName(id("authors")) + .withColumnName(id("name")) + .build(); + + var string = write(writer -> writer.writeExpression(sql)); + + assertThat(string, equalTo("authors.name")); + } + @Test public void intLiteral() throws IOException { var sql = SqlIntLiteral.arbitrary() diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlColumnReferenceMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlColumnReferenceMatcher.java new file mode 100644 index 0000000..35916c0 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlColumnReferenceMatcher.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.SqlColumnReferenceMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnReferenceMatcher imports + +public final class SqlColumnReferenceMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnReferenceMatcher isSqlColumnReference() { + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnReferenceMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private SqlColumnReferenceMatcher( + java.util.List> 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 toMatcher() { + return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnReference.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnReferenceMatcher withRelationName(org.zwobble.precisely.Matcher relationName) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("relationName", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnReference::relationName, (org.zwobble.precisely.Matcher) relationName)); + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnReferenceMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnReferenceMatcher withColumnName(org.zwobble.precisely.Matcher columnName) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("columnName", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnReference::columnName, (org.zwobble.precisely.Matcher) columnName)); + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnReferenceMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnReferenceMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlColumnReferenceMatcher body +} -- cgit v1.2.3