diff options
Diffstat (limited to 'src/test/java/org/zwobble')
2 files changed, 71 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 c17d96f..2568c42 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 @@ -537,6 +537,26 @@ public class RustWriterTests { assertThat(string, equalTo("x.y")); } + // === If expressions === + + @Test + public void ifExpression() throws IOException { + var rust = RustIfExpression.arbitrary() + .withCondition(RustPath.of("a")) + .withIfTrue(RustBlockExpression.arbitrary().withFinalOperand(RustPath.of("b"))) + .withIfFalse(RustBlockExpression.arbitrary().withFinalOperand(RustPath.of("c"))) + .build(); + + var string = write(writer -> writer.writeExpression(rust)); + + assertThat(string, equalTo(""" + if a { + b + } else { + c + }""")); + } + // === Integer literals === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIfExpressionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIfExpressionMatcher.java new file mode 100644 index 0000000..16fc324 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIfExpressionMatcher.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.RustIfExpressionMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpressionMatcher imports + +public class RustIfExpressionMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpressionMatcher isRustIfExpression() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpressionMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpression>> submatchers; + + private RustIfExpressionMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpression>> 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.RustIfExpression.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpressionMatcher withCondition(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression> condition) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpression>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("condition", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpression::condition, condition)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpressionMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpressionMatcher withIfTrue(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpression> ifTrue) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpression>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("ifTrue", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpression::ifTrue, ifTrue)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpressionMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpressionMatcher withIfFalse(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpression> ifFalse) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpression>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("ifFalse", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpression::ifFalse, ifFalse)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpressionMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpressionMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIfExpressionMatcher body +} |
