diff options
Diffstat (limited to 'src/test/java/org')
3 files changed, 115 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 5cb711a..c766157 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 @@ -644,6 +644,31 @@ public class RustWriterTests { }""")); } + // === Match expressions === + + @Test + public void matchExpression() throws IOException { + var rust = RustMatchExpression.arbitrary() + .withScrutinee(RustPath.of("x")) + .addArm(RustMatchArm.arbitrary() + .withPattern(RustPathPattern.arbitrary().withPath(RustPath.of("X", "Y"))) + .withBody(RustIntegerLiteral.arbitrary().withValue(1)) + ) + .addArm(RustMatchArm.arbitrary() + .withPattern(RustWildcardPattern.arbitrary()) + .withBody(RustIntegerLiteral.arbitrary().withValue(2)) + ) + .build(); + + var string = write(writer -> writer.writeTopLevelExpression(rust)); + + assertThat(string, equalTo(""" + match x { + X::Y => 1, + _ => 2, + }""")); + } + // === Prefix expressions === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustMatchArmMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustMatchArmMatcher.java new file mode 100644 index 0000000..697f6c5 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustMatchArmMatcher.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.RustMatchArmMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchArmMatcher imports + +public class RustMatchArmMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchArmMatcher isRustMatchArm() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchArmMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchArm>> submatchers; + + private RustMatchArmMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchArm>> 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.RustMatchArm.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchArmMatcher withPattern(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPattern> pattern) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchArm>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("pattern", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchArm::pattern, pattern)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchArmMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchArmMatcher 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.RustMatchArm>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("body", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchArm::body, body)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchArmMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchArmMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchArmMatcher body +} diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustMatchExpressionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustMatchExpressionMatcher.java new file mode 100644 index 0000000..8dcee56 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustMatchExpressionMatcher.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.RustMatchExpressionMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchExpressionMatcher imports + +public class RustMatchExpressionMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchExpressionMatcher isRustMatchExpression() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchExpressionMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchExpression>> submatchers; + + private RustMatchExpressionMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchExpression>> 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.RustMatchExpression.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchExpressionMatcher withScrutinee(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression> scrutinee) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchExpression>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("scrutinee", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchExpression::scrutinee, scrutinee)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchExpressionMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchExpressionMatcher withArms(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchArm>> arms) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchExpression>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("arms", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchExpression::arms, arms)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchExpressionMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchExpressionMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMatchExpressionMatcher body +} |
