summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-07-19 17:30:38 +0100
committerMichael Williamson <mike@zwobble.org>2026-07-19 17:30:38 +0100
commit1f005669637f624ac5fdd42cb999558cde6aed33 (patch)
tree2067aacd76f6be9bb092f75a5aa2c5f3a700519e /src/test/java
parentc4e0e6e62565c9e601ff45a366cf5dd31324c13c (diff)
Add literal patterns to Rust AST
Diffstat (limited to 'src/test/java')
-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/RustLiteralPatternMatcher.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 24a57a6..5cb711a 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
@@ -850,6 +850,19 @@ public class RustWriterTests {
assertThat(string, equalTo("x"));
}
+ // === Literal patterns ===
+
+ @Test
+ public void literalPattern() throws IOException {
+ var rust = RustLiteralPattern.arbitrary()
+ .withLiteral(RustBoolLiteral.arbitrary().withValue(false))
+ .build();
+
+ var string = write(writer -> writer.writePattern(rust));
+
+ assertThat(string, equalTo("false"));
+ }
+
// === Path patterns ===
@Test
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustLiteralPatternMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustLiteralPatternMatcher.java
new file mode 100644
index 0000000..5af5abc
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustLiteralPatternMatcher.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.RustLiteralPatternMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLiteralPatternMatcher imports
+
+public class RustLiteralPatternMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLiteralPatternMatcher isRustLiteralPattern() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLiteralPatternMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLiteralPattern>> submatchers;
+
+ private RustLiteralPatternMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLiteralPattern>> 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.RustLiteralPattern.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLiteralPatternMatcher withLiteral(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLiteralExpression> literal) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLiteralPattern>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("literal", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLiteralPattern::literal, literal));
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLiteralPatternMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLiteralPatternMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustLiteralPatternMatcher body
+}