diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-03 14:39:20 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-03 14:39:20 +0100 |
| commit | 53475694bb32e0df968a9d86b45e4a899fa166e9 (patch) | |
| tree | 9fb5aa40cf50197c8f99aaa48634745630a725c5 /src/test | |
| parent | 76259b1c4cb97d59573673fa7e645a394b27198e (diff) | |
Add call expressions to Rust AST
Diffstat (limited to 'src/test')
2 files changed, 69 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 2090c1e..2709df9 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 @@ -357,6 +357,30 @@ public class RustWriterTests { assertThat(string, equalTo("false")); } + @Test + public void callExpressionWithNoArgs() throws IOException { + var rust = RustCallExpression.arbitrary() + .withFunction(RustPathInExpression.of("f")) + .build(); + + var string = write(writer -> writer.writeExpression(rust)); + + assertThat(string, equalTo("f()")); + } + + @Test + public void callExpressionWithArgs() throws IOException { + var rust = RustCallExpression.arbitrary() + .withFunction(RustPathInExpression.of("f")) + .addArg(RustPathInExpression.of("x")) + .addArg(RustPathInExpression.of("y")) + .build(); + + var string = write(writer -> writer.writeExpression(rust)); + + assertThat(string, equalTo("f(x, y)")); + } + // == Paths == @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustCallExpressionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustCallExpressionMatcher.java new file mode 100644 index 0000000..a17d04d --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustCallExpressionMatcher.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.RustCallExpressionMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustCallExpressionMatcher imports + +public class RustCallExpressionMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustCallExpressionMatcher isRustCallExpression() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustCallExpressionMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustCallExpression>> submatchers; + + private RustCallExpressionMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustCallExpression>> 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.RustCallExpression.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustCallExpressionMatcher withFunction(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression> function) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustCallExpression>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("function", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustCallExpression::function, function)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustCallExpressionMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustCallExpressionMatcher withArgs(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression>> args) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustCallExpression>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("args", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustCallExpression::args, args)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustCallExpressionMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustCallExpressionMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustCallExpressionMatcher body +} |
