diff options
Diffstat (limited to 'src/test')
2 files changed, 112 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 a6f8069..33c1fe4 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 @@ -261,6 +261,73 @@ public class RustWriterTests { // == Expressions == @Test + public void blockExpressionWithNoStatementsAndNoFinalOperand() throws IOException { + var rust = RustBlockExpression.arbitrary().build(); + + var string = write(writer -> writer.writeExpression(rust)); + + assertThat(string, equalTo(""" + { + }""")); + } + + @Test + public void blockExpressionWithStatementsAndNoFinalOperand() throws IOException { + var rust = RustBlockExpression.arbitrary() + .addStatement(RustExpressionStatement.arbitrary() + .withExpression(RustBoolLiteral.arbitrary().withValue(true)) + ) + .addStatement(RustExpressionStatement.arbitrary() + .withExpression(RustBoolLiteral.arbitrary().withValue(false)) + ) + .build(); + + var string = write(writer -> writer.writeExpression(rust)); + + assertThat(string, equalTo(""" + { + true; + false; + }""")); + } + + @Test + public void blockExpressionWithNoStatementsAndFinalOperand() throws IOException { + var rust = RustBlockExpression.arbitrary() + .withFinalOperand(Optional.of(RustBoolLiteral.arbitrary().withValue(true).build())) + .build(); + + var string = write(writer -> writer.writeExpression(rust)); + + assertThat(string, equalTo(""" + { + true + }""")); + } + + @Test + public void blockExpressionWithStatementsAndFinalOperand() throws IOException { + var rust = RustBlockExpression.arbitrary() + .addStatement(RustExpressionStatement.arbitrary() + .withExpression(RustBoolLiteral.arbitrary().withValue(true)) + ) + .addStatement(RustExpressionStatement.arbitrary() + .withExpression(RustBoolLiteral.arbitrary().withValue(false)) + ) + .withFinalOperand(Optional.of(RustBoolLiteral.arbitrary().withValue(true).build())) + .build(); + + var string = write(writer -> writer.writeExpression(rust)); + + assertThat(string, equalTo(""" + { + true; + false; + true + }""")); + } + + @Test public void trueLiteral() throws IOException { var rust = RustBoolLiteral.arbitrary().withValue(true).build(); diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustBlockExpressionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustBlockExpressionMatcher.java new file mode 100644 index 0000000..f002dce --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustBlockExpressionMatcher.java @@ -0,0 +1,45 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.rust.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpressionMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpressionMatcher imports + +public class RustBlockExpressionMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpressionMatcher isRustBlockExpression() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpressionMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpression>> submatchers; + + private RustBlockExpressionMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpression>> 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.RustBlockExpression.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpressionMatcher withStatements(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustStatement>> statements) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpression>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("statements", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpression::statements, statements)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpressionMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpressionMatcher withFinalOperand(org.zwobble.precisely.Matcher<? super java.util.Optional<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression>> finalOperand) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpression>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("finalOperand", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpression::finalOperand, finalOperand)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpressionMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpressionMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpressionMatcher body +} |
