diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-14 19:47:53 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-14 19:47:53 +0100 |
| commit | 0e51a1497b98bd190d304acc4c1e1e1f56bf03c7 (patch) | |
| tree | bed1ed46a41ade2a4ca48e2da30541439177abde /src/test/java | |
| parent | 043bfe981db97daca8b543582d4114fd2aa3f7ec (diff) | |
Add attributes to Rust enums
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java | 19 | ||||
| -rw-r--r-- | src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustEnumMatcher.java | 6 |
2 files changed, 25 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 62b361a..776d51d 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 @@ -176,6 +176,25 @@ public class RustWriterTests { } @Test + public void enumWithAttributes() throws IOException { + var rust = RustEnum.arbitrary() + .withName(new RustIdentifier("Shape")) + .withAttributes(List.of( + new RustOuterAttribute(RustTypePath.of("a", "b", "C"), Optional.empty()), + new RustOuterAttribute(RustTypePath.of("derive"), Optional.of("(Debug)")) + )) + .build(); + + var string = write(writer -> writer.writeItem(rust)); + + assertThat(string, equalTo(""" + #[a::b::C] + #[derive(Debug)] + pub enum Shape { + }""")); + } + + @Test public void enumWithFieldlessVariants() throws IOException { var rust = RustEnum.arbitrary() .withName(new RustIdentifier("Shape")) diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustEnumMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustEnumMatcher.java index 547bdf7..9d1a8cd 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustEnumMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustEnumMatcher.java @@ -28,6 +28,12 @@ public class RustEnumMatcher implements org.zwobble.precisely.Matcher<java.lang. return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustEnum.class, this.submatchers); } + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustEnumMatcher withAttributes(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute>> attributes) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustEnum>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("attributes", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustEnum::attributes, attributes)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustEnumMatcher(submatchers); + } + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustEnumMatcher 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.RustEnum>>(this.submatchers); submatchers.add(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustEnum::name, name)); |
