summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java20
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFunctionMatcher.java39
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustInherentImplMatcher.java6
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
}