From 9105526554dc825095c02fdafb1fb7d1852aa134 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 9 Aug 2026 16:53:54 +0100 Subject: Add params to type aliases in Rust AST --- .../compiler/output/lang/rust/RustWriterTests.java | 14 ++++++++ .../output/lang/rust/ast/RustTypeAliasMatcher.java | 6 ++++ .../output/lang/rust/ast/RustTypeParamMatcher.java | 41 ++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypeParamMatcher.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 f06b4a1..5b1fe95 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 @@ -121,6 +121,20 @@ public class RustWriterTests { assertThat(string, equalTo("type X = Y;")); } + @Test + public void typeAliasWithUnboundedTypeParam() throws IOException { + var rust = RustTypeAlias.arbitrary() + .withName(RustIdentifier.of("X")) + .addParam(RustTypeParam.arbitrary().withName(RustIdentifier.of("T1"))) + .addParam(RustTypeParam.arbitrary().withName(RustIdentifier.of("T2"))) + .withType(RustPath.of("Y")) + .build(); + + var string = write(writer -> writer.writeItem(rust)); + + assertThat(string, equalTo("type X = Y;")); + } + // === Structs === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypeAliasMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypeAliasMatcher.java index 8cabb97..41ff267 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypeAliasMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypeAliasMatcher.java @@ -36,6 +36,12 @@ public final class RustTypeAliasMatcher implements org.zwobble.precisely.Matcher return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeAliasMatcher(submatchers); } + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeAliasMatcher withParams(org.zwobble.precisely.Matcher> params) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("params", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeAlias::params, params)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeAliasMatcher(submatchers); + } + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeAliasMatcher withType(org.zwobble.precisely.Matcher type) { var submatchers = new java.util.ArrayList>(this.submatchers); submatchers.add(org.zwobble.precisely.Matchers.has("type", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeAlias::type, type)); diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypeParamMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypeParamMatcher.java new file mode 100644 index 0000000..99e09bc --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypeParamMatcher.java @@ -0,0 +1,41 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.rust.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParamMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParamMatcher imports + +public final class RustTypeParamMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParamMatcher isRustTypeParam() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParamMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private RustTypeParamMatcher( + 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.RustTypeParam.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParamMatcher withName(org.zwobble.precisely.Matcher name) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam::name, name)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParamMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParamMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParamMatcher body +} -- cgit v1.2.3