summaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-07-19 21:35:22 +0100
committerMichael Williamson <mike@zwobble.org>2026-07-19 21:35:22 +0100
commit68efffb46ade1393c6412109dabf89a7c6d135e2 (patch)
treeadc411a073af892cf3b490659ed5dd3a0edb0ed2 /src/test/java/org/zwobble
parent891f59eec10c069057810c775366258e1154d6e3 (diff)
Add tuple struct patterns to Rust AST
Diffstat (limited to 'src/test/java/org/zwobble')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java39
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTupleStructPatternMatcher.java45
2 files changed, 84 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 c766157..1d04b72 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
@@ -901,6 +901,45 @@ public class RustWriterTests {
assertThat(string, equalTo("X::Y"));
}
+ // === Tuple struct patterns ===
+
+ @Test
+ public void tupleStructPatternWithNoItems() throws IOException {
+ var rust = RustTupleStructPattern.arbitrary()
+ .withConstructor(RustPath.of("X", "Y"))
+ .build();
+
+ var string = write(writer -> writer.writePattern(rust));
+
+ assertThat(string, equalTo("X::Y()"));
+ }
+
+ @Test
+ public void tupleStructPatternWithOneItem() throws IOException {
+ var rust = RustTupleStructPattern.arbitrary()
+ .withConstructor(RustPath.of("X", "Y"))
+ .addItem(RustIdentifierPattern.arbitrary().withVariableName(RustIdentifier.of("a")))
+ .build();
+
+ var string = write(writer -> writer.writePattern(rust));
+
+ assertThat(string, equalTo("X::Y(a)"));
+ }
+
+ @Test
+ public void tupleStructPatternWithMultipleItems() throws IOException {
+ var rust = RustTupleStructPattern.arbitrary()
+ .withConstructor(RustPath.of("X", "Y"))
+ .addItem(RustIdentifierPattern.arbitrary().withVariableName(RustIdentifier.of("a")))
+ .addItem(RustIdentifierPattern.arbitrary().withVariableName(RustIdentifier.of("b")))
+ .addItem(RustIdentifierPattern.arbitrary().withVariableName(RustIdentifier.of("c")))
+ .build();
+
+ var string = write(writer -> writer.writePattern(rust));
+
+ assertThat(string, equalTo("X::Y(a, b, c)"));
+ }
+
// === Wildcard patterns ===
@Test
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTupleStructPatternMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTupleStructPatternMatcher.java
new file mode 100644
index 0000000..b725214
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTupleStructPatternMatcher.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.RustTupleStructPatternMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTupleStructPatternMatcher imports
+
+public class RustTupleStructPatternMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTupleStructPatternMatcher isRustTupleStructPattern() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTupleStructPatternMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTupleStructPattern>> submatchers;
+
+ private RustTupleStructPatternMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTupleStructPattern>> 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.RustTupleStructPattern.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTupleStructPatternMatcher withConstructor(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPath> constructor) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTupleStructPattern>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("constructor", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTupleStructPattern::constructor, constructor));
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTupleStructPatternMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTupleStructPatternMatcher withItems(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPattern>> items) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTupleStructPattern>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("items", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTupleStructPattern::items, items));
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTupleStructPatternMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTupleStructPatternMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTupleStructPatternMatcher body
+}