diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-02 23:31:17 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-02 23:31:17 +0100 |
| commit | fdc4a5fe987f1b575068aab4c5bf02361cc25c85 (patch) | |
| tree | d5ebf3b0d51b78d7f3ca25832a1e329d58e5260e /src/test/java/org | |
| parent | 83ea0992f329e1b8148b8c6e91c8ecf7154706f5 (diff) | |
Add params to Rust functions
Diffstat (limited to 'src/test/java/org')
3 files changed, 66 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 1de04da..dd1729b 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 @@ -141,6 +141,21 @@ public class RustWriterTests { } @Test + public void functionWithParams() throws IOException { + var rust = RustFunction.arbitrary() + .withName(new RustIdentifier("area")) + .addParam(new RustFunctionParam(new RustIdentifier("width"), RustTypePath.of("i32"))) + .addParam(new RustFunctionParam(new RustIdentifier("height"), RustTypePath.of("u64"))) + .build(); + + var string = write(writer -> writer.writeAssociatedItem(rust)); + + assertThat(string, equalTo(""" + fn area(width: i32, height: u64) { + }""")); + } + + @Test public void emptyInherentImpl() throws IOException { var rust = RustInherentImpl.arbitrary().withType(RustTypePath.of("Square")).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 index 4777b24..ac6d126 100644 --- 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 @@ -34,6 +34,12 @@ public class RustFunctionMatcher implements org.zwobble.precisely.Matcher<java.l return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionMatcher(submatchers); } + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionMatcher withParams(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionParam>> params) { + 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("params", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunction::params, params)); + 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/RustFunctionParamMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFunctionParamMatcher.java new file mode 100644 index 0000000..64f7101 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFunctionParamMatcher.java @@ -0,0 +1,45 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.rust.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionParamMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionParamMatcher imports + +public class RustFunctionParamMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionParamMatcher isRustFunctionParam() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionParamMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionParam>> submatchers; + + private RustFunctionParamMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionParam>> 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.RustFunctionParam.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionParamMatcher 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.RustFunctionParam>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionParam::name, name)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionParamMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionParamMatcher withType(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustType> type) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionParam>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("type", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionParam::type, type)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionParamMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionParamMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionParamMatcher body +} |
