summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-08-09 14:12:44 +0100
committerMichael Williamson <mike@zwobble.org>2026-08-09 14:12:44 +0100
commit57d7f43d0944db2edd140e2380f5114229ae334d (patch)
tree907822897b781978c88fcd4a376c0f42ee0c8df0 /src/test
parent1fd5e5b3e6df869c6b48f8ce3b60078311a4a9ea (diff)
Add function pointer types to Rust AST
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java13
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFunctionPointerTypeMatcher.java47
2 files changed, 60 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 7272eea..0bf96e4 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
@@ -1070,6 +1070,19 @@ public class RustWriterTests {
// == Types ==
@Test
+ public void functionPointerType() throws IOException {
+ var rust = RustFunctionPointerType.arbitrary()
+ .addParam(RustPath.of("A"))
+ .addParam(RustPath.of("B"))
+ .withReturnType(RustPath.of("C"))
+ .build();
+
+ var string = write(writer -> writer.writeType(rust));
+
+ assertThat(string, equalTo("fn(A, B) -> C"));
+ }
+
+ @Test
public void implTraitType() throws IOException {
var rust = RustImplTraitType.arbitrary()
.withTrait(RustPath.of("std", "io", "Read"))
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFunctionPointerTypeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFunctionPointerTypeMatcher.java
new file mode 100644
index 0000000..72ff1ab
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFunctionPointerTypeMatcher.java
@@ -0,0 +1,47 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.rust.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher imports
+
+public final class RustFunctionPointerTypeMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher isRustFunctionPointerType() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerType>> submatchers;
+
+ private RustFunctionPointerTypeMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerType>> 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.RustFunctionPointerType.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher withParams(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustType>> params) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerType>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("params", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerType::params, params));
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher withReturnType(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustType> returnType) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerType>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("returnType", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerType::returnType, returnType));
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher body
+}