From 02e2a52b22c7e56c396add075446c667f1f54bad Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 14 Jul 2026 21:42:59 +0100 Subject: Add borrow expressions to Rust AST --- .../compiler/output/lang/rust/RustWriterTests.java | 14 +++++++ .../lang/rust/ast/RustPrefixExpressionMatcher.java | 45 ++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPrefixExpressionMatcher.java (limited to 'src/test/java') 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 625526b..7f85b8a 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 @@ -497,6 +497,20 @@ public class RustWriterTests { assertThat(string, equalTo("x.y")); } + // === Prefix expressions === + + @Test + public void borrowExpression() throws IOException { + var rust = RustPrefixExpression.arbitrary() + .withOperator(RustPrefixOperator.BORROW) + .withOperand(RustPath.of("x")) + .build(); + + var string = write(writer -> writer.writeExpression(rust)); + + assertThat(string, equalTo("&x")); + } + // === Struct expressions === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPrefixExpressionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPrefixExpressionMatcher.java new file mode 100644 index 0000000..dc3d418 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPrefixExpressionMatcher.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.RustPrefixExpressionMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPrefixExpressionMatcher imports + +public class RustPrefixExpressionMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPrefixExpressionMatcher isRustPrefixExpression() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPrefixExpressionMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private RustPrefixExpressionMatcher(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.RustPrefixExpression.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPrefixExpressionMatcher withOperator(org.zwobble.precisely.Matcher operator) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("operator", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPrefixExpression::operator, operator)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPrefixExpressionMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPrefixExpressionMatcher withOperand(org.zwobble.precisely.Matcher operand) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("operand", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPrefixExpression::operand, operand)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPrefixExpressionMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPrefixExpressionMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPrefixExpressionMatcher body +} -- cgit v1.2.3