From 152c1dc711f472d3ae441a94aefd7a8b54811ffb Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 2 Jul 2026 17:24:21 +0100 Subject: Support empty inherent impl in Rust AST --- .../compiler/output/lang/rust/RustWriterTests.java | 11 ++++++ .../lang/rust/ast/RustInherentImplMatcher.java | 39 ++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustInherentImplMatcher.java (limited to 'src/test/java') 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 b5583ab..ea04006 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 @@ -127,6 +127,17 @@ public class RustWriterTests { }""")); } + @Test + public void emptyInherentImpl() throws IOException { + var rust = RustInherentImpl.arbitrary().withType(RustTypePath.of("Square")).build(); + + var string = write(writer -> writer.writeItem(rust)); + + assertThat(string, equalTo(""" + impl Square { + }""")); + } + @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/RustInherentImplMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustInherentImplMatcher.java new file mode 100644 index 0000000..23b23a1 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustInherentImplMatcher.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.RustInherentImplMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImplMatcher imports + +public class RustInherentImplMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImplMatcher isRustInherentImpl() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImplMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private RustInherentImplMatcher(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.RustInherentImpl.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImplMatcher 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.RustInherentImpl::type, type)); + 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 +} -- cgit v1.2.3