summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-07-03 12:14:30 +0100
committerMichael Williamson <mike@zwobble.org>2026-07-03 12:14:30 +0100
commit8dc5c03a23d1ab5f07848bbc217059de96eed30a (patch)
treed9db3d34390baa0a88cec25e85886ba69296e423 /src/test
parentcaeef0039e93a78ffc9de251ffc8b09ed329a822 (diff)
Add expression statements to Rust AST
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java13
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustExpressionStatementMatcher.java39
2 files changed, 52 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 96cdc83..a6f8069 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
@@ -245,6 +245,19 @@ public class RustWriterTests {
}"""));
}
+ // == Statements ==
+
+ @Test
+ public void expressionStatementIsExpressionFollowedBySemicolon() throws IOException {
+ var rust = RustExpressionStatement.arbitrary()
+ .withExpression(RustBoolLiteral.arbitrary().withValue(true).build())
+ .build();
+
+ var string = write(writer -> writer.writeStatement(rust));
+
+ assertThat(string, equalTo("true;"));
+ }
+
// == Expressions ==
@Test
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustExpressionStatementMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustExpressionStatementMatcher.java
new file mode 100644
index 0000000..4e2479f
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustExpressionStatementMatcher.java
@@ -0,0 +1,39 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.rust.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpressionStatementMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpressionStatementMatcher imports
+
+public class RustExpressionStatementMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpressionStatementMatcher isRustExpressionStatement() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpressionStatementMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpressionStatement>> submatchers;
+
+ private RustExpressionStatementMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpressionStatement>> 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.RustExpressionStatement.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpressionStatementMatcher withExpression(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression> expression) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpressionStatement>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("expression", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpressionStatement::expression, expression));
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpressionStatementMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpressionStatementMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpressionStatementMatcher body
+}