From 25ce955d42281d15e87eff14faff08063faeec28 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 5 Dec 2026 20:25:18 +0000 Subject: Add WHERE clause to SELECT statements in SQL AST --- .../compiler/output/lang/sql/SqlWriterTests.java | 21 +++++++++++++++++++++ .../lang/sql/ast/SqlSelectStatementMatcher.java | 6 ++++++ 2 files changed, 27 insertions(+) (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 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 @@ -131,6 +131,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() 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> where) { + var submatchers = new java.util.ArrayList>(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 } -- cgit v1.2.3