From 8b6c82d1114320eeca2695f4e2c1db9eca4ab361 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 5 Dec 2026 20:11:56 +0000 Subject: Add equality operation to SQL AST --- .../compiler/output/lang/sql/SqlWriterTests.java | 13 ++++++ .../lang/sql/ast/SqlBinaryOperationMatcher.java | 53 ++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlBinaryOperationMatcher.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 20d6dac..4f9771a 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 @@ -201,6 +201,19 @@ public class SqlWriterTests { // === Expressions === + @Test + public void binaryOperationEquals() throws IOException { + var sql = SqlBinaryOperation.arbitrary() + .withOperator(SqlBinaryOperator.EQUALS) + .withLeft(SqlIntLiteral.arbitrary().withValue(42)) + .withRight(SqlIntLiteral.arbitrary().withValue(47)) + .build(); + + var string = write(writer -> writer.writeExpression(sql)); + + assertThat(string, equalTo("42 == 47")); + } + @Test public void intLiteral() throws IOException { var sql = SqlIntLiteral.arbitrary() diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlBinaryOperationMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlBinaryOperationMatcher.java new file mode 100644 index 0000000..fe79201 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlBinaryOperationMatcher.java @@ -0,0 +1,53 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.sql.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlBinaryOperationMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlBinaryOperationMatcher imports + +public final class SqlBinaryOperationMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlBinaryOperationMatcher isSqlBinaryOperation() { + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlBinaryOperationMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private SqlBinaryOperationMatcher( + 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.SqlBinaryOperation.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlBinaryOperationMatcher withOperator(org.zwobble.precisely.Matcher operator) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("operator", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlBinaryOperation::operator, (org.zwobble.precisely.Matcher) operator)); + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlBinaryOperationMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlBinaryOperationMatcher withLeft(org.zwobble.precisely.Matcher left) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("left", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlBinaryOperation::left, (org.zwobble.precisely.Matcher) left)); + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlBinaryOperationMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlBinaryOperationMatcher withRight(org.zwobble.precisely.Matcher right) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("right", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlBinaryOperation::right, (org.zwobble.precisely.Matcher) right)); + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlBinaryOperationMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlBinaryOperationMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlBinaryOperationMatcher body +} -- cgit v1.2.3