summaryrefslogtreecommitdiff
path: root/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java30
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustStructStructMatcher.java2
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);