From a2a1afd66b14746d247a395a46af1e3cccac9326 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 14 Jul 2026 21:49:44 +0100 Subject: Add reference types to Rust AST --- .../compiler/output/lang/rust/RustWriterTests.java | 22 ++++++++++++ .../rust/ast/RustMutableReferenceTypeMatcher.java | 39 ++++++++++++++++++++++ .../rust/ast/RustSharedReferenceTypeMatcher.java | 39 ++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustMutableReferenceTypeMatcher.java create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustSharedReferenceTypeMatcher.java (limited to 'src/test/java/org/zwobble') 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 7f85b8a..6900f83 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 @@ -558,6 +558,28 @@ public class RustWriterTests { assertThat(string, equalTo("impl std::io::Read")); } + @Test + public void mutableReferenceType() throws IOException { + var rust = RustMutableReferenceType.arbitrary() + .withReferencedType(RustPath.of("i32")) + .build(); + + var string = write(writer -> writer.writeType(rust)); + + assertThat(string, equalTo("&mut i32")); + } + + @Test + public void sharedReferenceType() throws IOException { + var rust = RustSharedReferenceType.arbitrary() + .withReferencedType(RustPath.of("i32")) + .build(); + + var string = write(writer -> writer.writeType(rust)); + + assertThat(string, equalTo("&i32")); + } + // == Paths == @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustMutableReferenceTypeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustMutableReferenceTypeMatcher.java new file mode 100644 index 0000000..875dac8 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustMutableReferenceTypeMatcher.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.RustMutableReferenceTypeMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMutableReferenceTypeMatcher imports + +public class RustMutableReferenceTypeMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMutableReferenceTypeMatcher isRustMutableReferenceType() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMutableReferenceTypeMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private RustMutableReferenceTypeMatcher(java.util.List> 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 toMatcher() { + return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMutableReferenceType.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMutableReferenceTypeMatcher withReferencedType(org.zwobble.precisely.Matcher referencedType) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("referencedType", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMutableReferenceType::referencedType, referencedType)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMutableReferenceTypeMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMutableReferenceTypeMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustMutableReferenceTypeMatcher body +} diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustSharedReferenceTypeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustSharedReferenceTypeMatcher.java new file mode 100644 index 0000000..1776707 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustSharedReferenceTypeMatcher.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.RustSharedReferenceTypeMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustSharedReferenceTypeMatcher imports + +public class RustSharedReferenceTypeMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustSharedReferenceTypeMatcher isRustSharedReferenceType() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustSharedReferenceTypeMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private RustSharedReferenceTypeMatcher(java.util.List> 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 toMatcher() { + return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustSharedReferenceType.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustSharedReferenceTypeMatcher withReferencedType(org.zwobble.precisely.Matcher referencedType) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("referencedType", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustSharedReferenceType::referencedType, referencedType)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustSharedReferenceTypeMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustSharedReferenceTypeMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustSharedReferenceTypeMatcher body +} -- cgit v1.2.3