From 53475694bb32e0df968a9d86b45e4a899fa166e9 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 3 Jul 2026 14:39:20 +0100 Subject: Add call expressions to Rust AST --- .../compiler/output/lang/rust/RustWriterTests.java | 24 ++++++++++++ .../lang/rust/ast/RustCallExpressionMatcher.java | 45 ++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustCallExpressionMatcher.java (limited to 'src/test') 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 { + 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> submatchers; + + private RustCallExpressionMatcher(java.util.List> 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 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 function) { + var submatchers = new java.util.ArrayList>(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> args) { + var submatchers = new java.util.ArrayList>(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 +} -- cgit v1.2.3