summaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-12-05 20:25:18 +0000
committerMichael Williamson <mike@zwobble.org>2026-12-05 20:26:11 +0000
commit25ce955d42281d15e87eff14faff08063faeec28 (patch)
tree9a319e4612f13f6fc44769ef534c91f584eb078c /src/test/java/org/zwobble
parent7d52459a8b62ed5bed2bbfcd830a0178ba6ca4c6 (diff)
Add WHERE clause to SELECT statements in SQL AST
Diffstat (limited to 'src/test/java/org/zwobble')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriterTests.java21
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlSelectStatementMatcher.java6
2 files changed, 27 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
index 2a96c4b..afbf80a 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
@@ -132,6 +132,27 @@ public class SqlWriterTests {
}
@Test
+ public void selectStatementWithWhereExpression() throws IOException {
+ var sql = SqlSelectStatement.arbitrary()
+ .addColumn(SqlResultColumn.arbitrary()
+ .withExpression(ref("a"))
+ .withAlias(id("x"))
+ )
+ .withFrom(id("blah"))
+ .withWhere(SqlIntLiteral.arbitrary().withValue(1))
+ .build();
+
+ var string = write(writer -> writer.writeStatement(sql));
+
+ assertThat(string, equalTo("""
+ SELECT
+ a AS x
+ FROM blah
+ WHERE 1;"""
+ ));
+ }
+
+ @Test
public void selectStatementWithSingleOrderByExpression() throws IOException {
var sql = SqlSelectStatement.arbitrary()
.addColumn(SqlResultColumn.arbitrary()
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlSelectStatementMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlSelectStatementMatcher.java
index db254ca..75f6761 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlSelectStatementMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlSelectStatementMatcher.java
@@ -48,6 +48,12 @@ public final class SqlSelectStatementMatcher implements org.zwobble.precisely.Ma
return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatementMatcher(submatchers);
}
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatementMatcher withWhere(org.zwobble.precisely.Matcher<? super java.util.Optional<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression>> where) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("where", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement::where, (org.zwobble.precisely.Matcher) where));
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatementMatcher(submatchers);
+ }
+
// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatementMatcher body
// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatementMatcher body
}