diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-31 10:57:39 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-31 10:57:39 +0100 |
| commit | 2f76934bf2aa59f78b671c722b73f0d69c7adbd3 (patch) | |
| tree | 6784f78eafe1bd2d906f410440b101b660e09077 /src/test/java/org/zwobble | |
| parent | 578bf1f04b48f48225cfa794a27426cca4f6384a (diff) | |
Handle singleton structs in Rust
Diffstat (limited to 'src/test/java/org/zwobble')
2 files changed, 22 insertions, 10 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 4a81031..56d6d87 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 @@ -28,11 +28,9 @@ public class RustWriterTests { assertThat(string, equalTo(""" // Generated by hobgoblin. - pub struct Rectangle { - } + pub struct Rectangle; - pub struct Square { - } + pub struct Square; """)); } @@ -112,8 +110,24 @@ public class RustWriterTests { // === Structs === @Test + public void unitLikeStruct() throws IOException { + var rust = RustStructStruct.arbitrary() + .withName(new RustIdentifier("Rectangle")) + .withFields(Optional.empty()) + .build(); + + var string = write(writer -> writer.writeItem(rust)); + + assertThat(string, equalTo(""" + pub struct Rectangle;""")); + } + + @Test public void emptyStruct() throws IOException { - var rust = RustStructStruct.arbitrary().withName(new RustIdentifier("Rectangle")).build(); + var rust = RustStructStruct.arbitrary() + .withName(new RustIdentifier("Rectangle")) + .withFields(List.of()) + .build(); var string = write(writer -> writer.writeItem(rust)); @@ -137,8 +151,7 @@ public class RustWriterTests { assertThat(string, equalTo(""" #[a::b::C] #[derive(Debug)] - pub struct Rectangle { - }""")); + pub struct Rectangle;""")); } @Test @@ -171,8 +184,7 @@ public class RustWriterTests { assertThat(string, equalTo(""" /// A 2D rectangle. - pub struct Rectangle { - }""")); + pub struct Rectangle;""")); } // === Enumerations === 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 b2109c1..6f04455 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,7 +42,7 @@ public class RustStructStructMatcher implements org.zwobble.precisely.Matcher<ja 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.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustStructField>> fields) { + 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)); return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustStructStructMatcher(submatchers); |
