diff options
Diffstat (limited to 'src/test')
2 files changed, 74 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 bf93c1d..e947db9 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 @@ -621,6 +621,29 @@ public class RustWriterTests { assertThat(string, equalTo("123i32")); } + // === Iterator expressions === + + @Test + public void iteratorExpression() throws IOException { + var rust = RustIteratorLoopExpression.arbitrary() + .withElementName(RustIdentifier.of("x")) + .withElements(RustPath.of("xs")) + .withBody(RustBlockExpression.arbitrary() + .withFinalOperand(RustCallExpression.arbitrary() + .withFunction(RustPath.of("print")) + .addArg(RustPath.of("x")) + ) + ) + .build(); + + var string = write(writer -> writer.writeTopLevelExpression(rust)); + + assertThat(string, equalTo(""" + for x in xs { + print(x) + }""")); + } + // === Prefix expressions === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIteratorLoopExpressionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIteratorLoopExpressionMatcher.java new file mode 100644 index 0000000..6bd153a --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIteratorLoopExpressionMatcher.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.RustIteratorLoopExpressionMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpressionMatcher imports + +public class RustIteratorLoopExpressionMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpressionMatcher isRustIteratorLoopExpression() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpressionMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpression>> submatchers; + + private RustIteratorLoopExpressionMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpression>> 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.RustIteratorLoopExpression.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpressionMatcher withElementName(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIdentifier> elementName) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpression>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("elementName", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpression::elementName, elementName)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpressionMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpressionMatcher withElements(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression> elements) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpression>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("elements", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpression::elements, elements)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpressionMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpressionMatcher withBody(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpression> body) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpression>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("body", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpression::body, body)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpressionMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpressionMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIteratorLoopExpressionMatcher body +} |
