diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-02 17:31:01 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-02 17:31:01 +0100 |
| commit | 34b45be0454f5a3a48fa2ab5dd14a7700fd9c6ee (patch) | |
| tree | 19feaa0f923b377a3b0837d565adce5e6a4ffefe /src/test/java | |
| parent | 152c1dc711f472d3ae441a94aefd7a8b54811ffb (diff) | |
Add associated items to Rust inherent impls
Diffstat (limited to 'src/test/java')
3 files changed, 65 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 ea04006..9d1565c 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 @@ -139,6 +139,26 @@ public class RustWriterTests { } @Test + public void inherentImplWithAssociatedItems() throws IOException { + var rust = RustInherentImpl.arbitrary() + .withType(RustTypePath.of("Square")) + .addItem(RustFunction.arbitrary().withName(new RustIdentifier("width"))) + .addItem(RustFunction.arbitrary().withName(new RustIdentifier("height"))) + .build(); + + var string = write(writer -> writer.writeItem(rust)); + + assertThat(string, equalTo(""" + impl Square { + fn width() { + } + + fn height() { + } + }""")); + } + + @Test public void emptyStruct() throws IOException { var rust = RustStructStruct.arbitrary().withName(new RustIdentifier("Rectangle")).build(); diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFunctionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFunctionMatcher.java new file mode 100644 index 0000000..4777b24 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFunctionMatcher.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.RustFunctionMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionMatcher imports + +public class RustFunctionMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionMatcher isRustFunction() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunction>> submatchers; + + private RustFunctionMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunction>> 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.RustFunction.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionMatcher withName(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIdentifier> name) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunction>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunction::name, name)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionMatcher body +} diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustInherentImplMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustInherentImplMatcher.java index 23b23a1..ee4b9f1 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustInherentImplMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustInherentImplMatcher.java @@ -34,6 +34,12 @@ public class RustInherentImplMatcher implements org.zwobble.precisely.Matcher<ja return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImplMatcher(submatchers); } + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImplMatcher withItems(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustAssociatedItem>> items) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImpl>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("items", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImpl::items, items)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImplMatcher(submatchers); + } + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImplMatcher body // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImplMatcher body } |
