diff options
Diffstat (limited to 'src/test')
2 files changed, 84 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 1d04b72..481d99e 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 @@ -564,6 +564,45 @@ public class RustWriterTests { assertThat(string, equalTo("f(x, y)")); } + // === Closure expressions === + + @Test + public void closureExpressionWithNoParams() throws IOException { + var rust = RustClosureExpression.arbitrary() + .withBody(RustPath.of("a")) + .build(); + + var string = write(writer -> writer.writeTopLevelExpression(rust)); + + assertThat(string, equalTo("|| a")); + } + + @Test + public void closureExpressionWithOneParam() throws IOException { + var rust = RustClosureExpression.arbitrary() + .addParam(RustIdentifierPattern.arbitrary().withVariableName(RustIdentifier.of("a"))) + .withBody(RustPath.of("a")) + .build(); + + var string = write(writer -> writer.writeTopLevelExpression(rust)); + + assertThat(string, equalTo("|a| a")); + } + + @Test + public void closureExpressionWithMultipleParams() throws IOException { + var rust = RustClosureExpression.arbitrary() + .addParam(RustIdentifierPattern.arbitrary().withVariableName(RustIdentifier.of("a"))) + .addParam(RustIdentifierPattern.arbitrary().withVariableName(RustIdentifier.of("b"))) + .addParam(RustIdentifierPattern.arbitrary().withVariableName(RustIdentifier.of("c"))) + .withBody(RustPath.of("a")) + .build(); + + var string = write(writer -> writer.writeTopLevelExpression(rust)); + + assertThat(string, equalTo("|a, b, c| a")); + } + // === Field expressions === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustClosureExpressionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustClosureExpressionMatcher.java new file mode 100644 index 0000000..d50cc13 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustClosureExpressionMatcher.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.RustClosureExpressionMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustClosureExpressionMatcher imports + +public class RustClosureExpressionMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustClosureExpressionMatcher isRustClosureExpression() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustClosureExpressionMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustClosureExpression>> submatchers; + + private RustClosureExpressionMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustClosureExpression>> 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.RustClosureExpression.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustClosureExpressionMatcher withParams(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPattern>> params) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustClosureExpression>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("params", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustClosureExpression::params, params)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustClosureExpressionMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustClosureExpressionMatcher withBody(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression> body) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustClosureExpression>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("body", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustClosureExpression::body, body)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustClosureExpressionMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustClosureExpressionMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustClosureExpressionMatcher body +} |
