summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-07-14 20:51:50 +0100
committerMichael Williamson <mike@zwobble.org>2026-07-14 20:51:50 +0100
commit7b4c0375059aaaf06cb8b8ccebebfbc0d20e01f2 (patch)
tree8b95ee817e6523d1dc9ff53441ce71beb066fd10 /src/test/java
parent6f7cc0826ffbcb6ab442d91da7b5385208f2af23 (diff)
Add field expressions to Rust AST
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java20
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFieldExpressionMatcher.java45
2 files changed, 65 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 da07c8a..21f8833 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
@@ -351,6 +351,8 @@ public class RustWriterTests {
// == Expressions ==
+ // === Block expressions ===
+
@Test
public void blockExpressionWithNoStatementsAndNoFinalOperand() throws IOException {
var rust = RustBlockExpression.arbitrary().build();
@@ -418,6 +420,8 @@ public class RustWriterTests {
}"""));
}
+ // === Boolean literals ===
+
@Test
public void trueLiteral() throws IOException {
var rust = RustBoolLiteral.arbitrary().withValue(true).build();
@@ -436,6 +440,8 @@ public class RustWriterTests {
assertThat(string, equalTo("false"));
}
+ // === Call expressions ===
+
@Test
public void callExpressionWithNoArgs() throws IOException {
var rust = RustCallExpression.arbitrary()
@@ -460,6 +466,20 @@ public class RustWriterTests {
assertThat(string, equalTo("f(x, y)"));
}
+ // === Field expressions ===
+
+ @Test
+ public void fieldExpression() throws IOException {
+ var rust = RustFieldExpression.arbitrary()
+ .withContainerOperand(RustPathInExpression.of("x"))
+ .withFieldName(RustIdentifier.of("y"))
+ .build();
+
+ var string = write(writer -> writer.writeExpression(rust));
+
+ assertThat(string, equalTo("x.y"));
+ }
+
// == Types ==
@Test
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFieldExpressionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFieldExpressionMatcher.java
new file mode 100644
index 0000000..ce26347
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFieldExpressionMatcher.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.RustFieldExpressionMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher imports
+
+public class RustFieldExpressionMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher isRustFieldExpression() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpression>> submatchers;
+
+ private RustFieldExpressionMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpression>> 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.RustFieldExpression.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher withContainerOperand(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression> containerOperand) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpression>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("containerOperand", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpression::containerOperand, containerOperand));
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher withFieldName(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIdentifier> fieldName) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpression>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("fieldName", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpression::fieldName, fieldName));
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher body
+}