summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-08-14 11:01:46 +0100
committerMichael Williamson <mike@zwobble.org>2026-08-14 11:01:46 +0100
commit00cfa7a56b31f0b629a54a77e1934d25471f8156 (patch)
treeb0074167b96b6c131cae54de7bab51858dae66e7 /src/test/java
parent8811a6c2b0a80297d239cbcda169dca8c809458a (diff)
Add type params to struct in Rust AST
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java16
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustStructStructMatcher.java6
2 files changed, 22 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 b8179f2..feabc12 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
@@ -213,6 +213,22 @@ public class RustWriterTests {
}
@Test
+ public void structWithTypeParams() throws IOException {
+ var rust = RustStructStruct.arbitrary()
+ .withName(RustIdentifier.of("X"))
+ .addTypeParam(RustTypeParam.arbitrary().withName(RustIdentifier.of("T1")))
+ .addTypeParam(RustTypeParam.arbitrary().withName(RustIdentifier.of("T2")))
+ .withFields(List.of())
+ .build();
+
+ var string = write(writer -> writer.writeItem(rust));
+
+ assertThat(string, equalTo("""
+ pub struct X<T1, T2> {
+ }"""));
+ }
+
+ @Test
public void structWithFields() throws IOException {
var rust = RustStructStruct.arbitrary()
.withName(new RustIdentifier("Rectangle"))
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustStructStructMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustStructStructMatcher.java
index b4c984d..b10f3c6 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustStructStructMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustStructStructMatcher.java
@@ -42,6 +42,12 @@ public final class RustStructStructMatcher implements org.zwobble.precisely.Matc
return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustStructStructMatcher(submatchers);
}
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustStructStructMatcher withTypeParams(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam>> typeParams) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustStructStruct>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("typeParams", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustStructStruct::typeParams, typeParams));
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustStructStructMatcher(submatchers);
+ }
+
public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustStructStructMatcher withFields(org.zwobble.precisely.Matcher<? super java.util.Optional<java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustStructField>>> fields) {
var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustStructStruct>>(this.submatchers);
submatchers.add(org.zwobble.precisely.Matchers.has("fields", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustStructStruct::fields, fields));