summaryrefslogtreecommitdiff
path: root/src/test/java/org
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-07-14 22:35:53 +0100
committerMichael Williamson <mike@zwobble.org>2026-07-14 22:35:53 +0100
commitedcaf92f6189a9f1af4978606d4948b56aca07b1 (patch)
treed165f1d1262f1ce49c9c0bb83453ce9079527575 /src/test/java/org
parent98b7b7bcf1ea27533c04757628b0ad2cf72fe09a (diff)
Support mutable lets in Rust AST
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java15
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustLetStatementMatcher.java6
2 files changed, 20 insertions, 1 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 e4cee1e..c17d96f 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
@@ -367,16 +367,29 @@ public class RustWriterTests {
// === Let statements ===
@Test
- public void letStatementDeclaringSingleVariable() throws IOException {
+ public void letStatementDeclaringSingleImmutableVariable() throws IOException {
var rust = RustLetStatement.arbitrary()
.withVariableName(RustIdentifier.of("x"))
+ .withMutable(false)
.withValue(RustBoolLiteral.arbitrary().withValue(true).build())
.build();
var string = write(writer -> writer.writeStatement(rust));
assertThat(string, equalTo("let x = true;"));
+ }
+
+ @Test
+ public void letStatementDeclaringSingleMutableVariable() throws IOException {
+ var rust = RustLetStatement.arbitrary()
+ .withVariableName(RustIdentifier.of("x"))
+ .withMutable(true)
+ .withValue(RustBoolLiteral.arbitrary().withValue(true).build())
+ .build();
+
+ var string = write(writer -> writer.writeStatement(rust));
+ assertThat(string, equalTo("let mut x = true;"));
}
// == Expressions ==
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustLetStatementMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustLetStatementMatcher.java
index c71dd98..b48d485 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustLetStatementMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustLetStatementMatcher.java
@@ -34,6 +34,12 @@ public class RustLetStatementMatcher implements org.zwobble.precisely.Matcher<ja
return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLetStatementMatcher(submatchers);
}
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLetStatementMatcher withMutable(org.zwobble.precisely.Matcher<? super java.lang.Boolean> mutable) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLetStatement>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("mutable", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLetStatement::mutable, mutable));
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLetStatementMatcher(submatchers);
+ }
+
public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLetStatementMatcher withValue(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression> value) {
var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLetStatement>>(this.submatchers);
submatchers.add(org.zwobble.precisely.Matchers.has("value", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLetStatement::value, value));