From 051ea60dc8a775f0fc82ebbc5f65a8c5f57157c0 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 25 Jul 2026 23:48:53 +0100 Subject: Add type cases to Rust AST --- .../compiler/output/lang/rust/RustWriterTests.java | 14 +++++++ .../rust/ast/RustTypeCastExpressionMatcher.java | 45 ++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypeCastExpressionMatcher.java (limited to 'src/test') 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 fe1f9b4..55c8f54 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 @@ -842,6 +842,20 @@ public class RustWriterTests { assertThat(string, equalTo("(a, b, c)")); } + // === Type cast expressions === + + @Test + public void typeCastExpression() throws IOException { + var rust = RustTypeCastExpression.arbitrary() + .withLeft(RustPath.of("a")) + .withRight(RustPath.of("X")) + .build(); + + var string = write(writer -> writer.writeTopLevelExpression(rust)); + + assertThat(string, equalTo("a as X")); + } + // === Vec repeat expressions === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypeCastExpressionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypeCastExpressionMatcher.java new file mode 100644 index 0000000..2ff190e --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypeCastExpressionMatcher.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.RustTypeCastExpressionMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeCastExpressionMatcher imports + +public class RustTypeCastExpressionMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeCastExpressionMatcher isRustTypeCastExpression() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeCastExpressionMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private RustTypeCastExpressionMatcher(java.util.List> 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 toMatcher() { + return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeCastExpression.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeCastExpressionMatcher withLeft(org.zwobble.precisely.Matcher left) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("left", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeCastExpression::left, left)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeCastExpressionMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeCastExpressionMatcher withRight(org.zwobble.precisely.Matcher right) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("right", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeCastExpression::right, right)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeCastExpressionMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeCastExpressionMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeCastExpressionMatcher body +} -- cgit v1.2.3