summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-07-03 14:33:09 +0100
committerMichael Williamson <mike@zwobble.org>2026-07-03 14:35:48 +0100
commit76259b1c4cb97d59573673fa7e645a394b27198e (patch)
tree667e156541b10f06535dbbdcbbf80dabd9c47e08 /src/test/java
parent98ca09b7b1ff3b82e3bb4de728417b176d56d4e7 (diff)
Add Rust path expressions
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java41
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathExprSegmentMatcher.java45
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathInExpressionMatcher.java39
3 files changed, 114 insertions, 11 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 476a876..2090c1e 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
@@ -360,34 +360,35 @@ public class RustWriterTests {
// == Paths ==
@Test
- public void typeSegmentsAreSeparatedByDoubleColons() throws IOException {
- var rust = RustTypePath.of("std", "string", "String");
+ public void pathExprSegmentsAreSeparatedByDoubleColons() throws IOException {
+ var rust = RustPathInExpression.of("std", "string", "String");
- var string = write(writer -> writer.writeType(rust));
+ var string = write(writer -> writer.writeExpression(rust));
assertThat(string, equalTo("std::string::String"));
}
@Test
- public void crateTypeSegmentIsWritten() throws IOException {
- var rust = RustTypePath.crate("a", "b");
+ public void pathExprSegmentGenericArgsAreWritten() throws IOException {
+ var rust = RustPathInExpression.of("std", "collections", "HashMap")
+ .withArgs(List.of(RustTypePath.of("i32"), RustTypePath.of("f64")));
- var string = write(writer -> writer.writeType(rust));
+ var string = write(writer -> writer.writeExpression(rust));
- assertThat(string, equalTo("crate::a::b"));
+ assertThat(string, equalTo("std::collections::HashMap::<i32, f64>"));
}
@Test
- public void globalTypeSegmentIsWritten() throws IOException {
- var rust = RustTypePath.global("a", "b");
+ public void typePathSegmentsAreSeparatedByDoubleColons() throws IOException {
+ var rust = RustTypePath.of("std", "string", "String");
var string = write(writer -> writer.writeType(rust));
- assertThat(string, equalTo("::a::b"));
+ assertThat(string, equalTo("std::string::String"));
}
@Test
- public void typeSegmentGenericArgsAreWritten() throws IOException {
+ public void typePathSegmentGenericArgsAreWritten() throws IOException {
var rust = RustTypePath.of("std", "collections", "HashMap")
.withArgs(List.of(RustTypePath.of("i32"), RustTypePath.of("f64")));
@@ -396,6 +397,24 @@ public class RustWriterTests {
assertThat(string, equalTo("std::collections::HashMap<i32, f64>"));
}
+ @Test
+ public void crateSegmentIsWritten() throws IOException {
+ var rust = RustTypePath.crate("a", "b");
+
+ var string = write(writer -> writer.writeType(rust));
+
+ assertThat(string, equalTo("crate::a::b"));
+ }
+
+ @Test
+ public void globalSegmentIsWritten() throws IOException {
+ var rust = RustTypePath.global("a", "b");
+
+ var string = write(writer -> writer.writeType(rust));
+
+ assertThat(string, equalTo("::a::b"));
+ }
+
// == Identifiers ==
@Test
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathExprSegmentMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathExprSegmentMatcher.java
new file mode 100644
index 0000000..04fbe5b
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathExprSegmentMatcher.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.RustPathExprSegmentMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegmentMatcher imports
+
+public class RustPathExprSegmentMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegmentMatcher isRustPathExprSegment() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegmentMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment>> submatchers;
+
+ private RustPathExprSegmentMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment>> 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.RustPathExprSegment.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegmentMatcher withPathIdentSegment(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegment> pathIdentSegment) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("pathIdentSegment", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment::pathIdentSegment, pathIdentSegment));
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegmentMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegmentMatcher withArgs(org.zwobble.precisely.Matcher<? super java.util.Optional<java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustType>>> args) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("args", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment::args, args));
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegmentMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegmentMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegmentMatcher body
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathInExpressionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathInExpressionMatcher.java
new file mode 100644
index 0000000..4fad401
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathInExpressionMatcher.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.RustPathInExpressionMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpressionMatcher imports
+
+public class RustPathInExpressionMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpressionMatcher isRustPathInExpression() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpressionMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression>> submatchers;
+
+ private RustPathInExpressionMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression>> 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.RustPathInExpression.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpressionMatcher withSegments(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment>> segments) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("segments", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression::segments, segments));
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpressionMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpressionMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpressionMatcher body
+}