diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-18 10:08:40 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-18 10:08:40 +0100 |
| commit | f1cd9657920232dbc7fa792ed2def4e8b34b19cd (patch) | |
| tree | 9916141227e9edb91f729e524954f0749ac2216f /src/test | |
| parent | d4a22c167efa7707d75fb952e5e98ec95b0c7dfd (diff) | |
Add equal and not equal operators to Rust AST
Diffstat (limited to 'src/test')
2 files changed, 79 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java index 16c774f..fff5923 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java @@ -408,6 +408,34 @@ public class RustWriterTests { assertThat(string, equalTo("[42; 47]")); } + // === Binary expressions === + + @Test + public void binaryExpressionEqual() throws IOException { + var rust = RustBinaryExpression.arbitrary() + .withOperator(RustBinaryOperator.EQUAL) + .withLeft(RustPath.of("x")) + .withRight(RustPath.of("y")) + .build(); + + var string = write(writer -> writer.writeExpression(rust)); + + assertThat(string, equalTo("x == y")); + } + + @Test + public void binaryExpressionNotEqual() throws IOException { + var rust = RustBinaryExpression.arbitrary() + .withOperator(RustBinaryOperator.NOT_EQUAL) + .withLeft(RustPath.of("x")) + .withRight(RustPath.of("y")) + .build(); + + var string = write(writer -> writer.writeExpression(rust)); + + assertThat(string, equalTo("x != y")); + } + // === Block expressions === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustBinaryExpressionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustBinaryExpressionMatcher.java new file mode 100644 index 0000000..172f969 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustBinaryExpressionMatcher.java @@ -0,0 +1,51 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.rust.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpressionMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpressionMatcher imports + +public class RustBinaryExpressionMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpressionMatcher isRustBinaryExpression() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpressionMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpression>> submatchers; + + private RustBinaryExpressionMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpression>> 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<java.lang.Object> toMatcher() { + return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpression.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpressionMatcher withOperator(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryOperator> operator) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpression>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("operator", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpression::operator, operator)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpressionMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpressionMatcher withLeft(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression> left) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpression>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("left", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpression::left, left)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpressionMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpressionMatcher withRight(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression> right) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpression>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("right", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpression::right, right)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpressionMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpressionMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBinaryExpressionMatcher body +} |
