From 5a646ae3ae92b9756e005b38e40f9fd8476cdc7c Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 5 Dec 2026 21:37:21 +0000 Subject: Add param refs to SQL AST --- .../compiler/output/lang/sql/SqlWriterTests.java | 11 ++++++ .../output/lang/sql/ast/SqlParamRefMatcher.java | 41 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlParamRefMatcher.java (limited to 'src/test/java') 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 afbf80a..964f3c1 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 @@ -258,6 +258,17 @@ public class SqlWriterTests { assertThat(string, equalTo("42")); } + @Test + public void paramRef() throws IOException { + var sql = SqlParamRef.arbitrary() + .withNumber(42) + .build(); + + var string = write(writer -> writer.writeExpression(sql)); + + assertThat(string, equalTo("?42")); + } + @Test public void ref() throws IOException { var sql = ref("a"); diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlParamRefMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlParamRefMatcher.java new file mode 100644 index 0000000..edcddbd --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlParamRefMatcher.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.SqlParamRefMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlParamRefMatcher imports + +public final class SqlParamRefMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlParamRefMatcher isSqlParamRef() { + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlParamRefMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private SqlParamRefMatcher( + 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.SqlParamRef.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlParamRefMatcher withNumber(org.zwobble.precisely.Matcher number) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("number", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlParamRef::number, (org.zwobble.precisely.Matcher) number)); + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlParamRefMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlParamRefMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlParamRefMatcher body +} -- cgit v1.2.3