From 28fee7435236bd1382a9e7281c8875564c607686 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 18 Jul 2026 11:07:04 +0100 Subject: Add vec repeat expression to Rust AST --- .../compiler/output/lang/rust/RustWriterTests.java | 14 +++++++ .../rust/ast/RustVecRepeatExpressionMatcher.java | 45 ++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustVecRepeatExpressionMatcher.java (limited to 'src/test/java/org') 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 4279f49..bf93c1d 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 @@ -741,6 +741,20 @@ public class RustWriterTests { assertThat(string, equalTo("(a, b, c)")); } + // === Vec repeat expressions === + + @Test + public void vecRepeatExpression() throws IOException { + var rust = RustVecRepeatExpression.arbitrary() + .withRepeatOperand(RustIntegerLiteral.arbitrary().withValue(42)) + .withLengthOperand(RustIntegerLiteral.arbitrary().withValue(47)) + .build(); + + var string = write(writer -> writer.writeTopLevelExpression(rust)); + + assertThat(string, equalTo("vec![42; 47]")); + } + // === Precedence handling === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustVecRepeatExpressionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustVecRepeatExpressionMatcher.java new file mode 100644 index 0000000..9519a7b --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustVecRepeatExpressionMatcher.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.RustVecRepeatExpressionMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustVecRepeatExpressionMatcher imports + +public class RustVecRepeatExpressionMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustVecRepeatExpressionMatcher isRustVecRepeatExpression() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustVecRepeatExpressionMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private RustVecRepeatExpressionMatcher(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.RustVecRepeatExpression.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustVecRepeatExpressionMatcher withRepeatOperand(org.zwobble.precisely.Matcher repeatOperand) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("repeatOperand", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustVecRepeatExpression::repeatOperand, repeatOperand)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustVecRepeatExpressionMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustVecRepeatExpressionMatcher withLengthOperand(org.zwobble.precisely.Matcher lengthOperand) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("lengthOperand", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustVecRepeatExpression::lengthOperand, lengthOperand)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustVecRepeatExpressionMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustVecRepeatExpressionMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustVecRepeatExpressionMatcher body +} -- cgit v1.2.3