diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-17 18:39:02 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-17 18:39:02 +0100 |
| commit | c82fcaa28e77fce24db5956862ca6355c1a8397d (patch) | |
| tree | 26a5552bd92ac00909db0ad4b27dc956b5174c96 /src/test/java/org/zwobble | |
| parent | 2ae4cc56fe917612e666d71540778298a79fdea4 (diff) | |
Support integer literal with explicit type in Rust AST
Diffstat (limited to 'src/test/java/org/zwobble')
2 files changed, 19 insertions, 1 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 eebc834..67f3f30 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 @@ -560,7 +560,7 @@ public class RustWriterTests { // === Integer literals === @Test - public void integerLiteral() throws IOException { + public void integerLiteralWithoutExplicitType() throws IOException { var rust = RustIntegerLiteral.arbitrary().withValue(123).build(); var string = write(writer -> writer.writeExpression(rust)); @@ -568,6 +568,18 @@ public class RustWriterTests { assertThat(string, equalTo("123")); } + @Test + public void integerLiteralWithExplicitType() throws IOException { + var rust = RustIntegerLiteral.arbitrary() + .withValue(123) + .withType(RustIdentifier.of("i32")) + .build(); + + var string = write(writer -> writer.writeExpression(rust)); + + assertThat(string, equalTo("123i32")); + } + // === Prefix expressions === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIntegerLiteralMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIntegerLiteralMatcher.java index f27b21f..4e31a41 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIntegerLiteralMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIntegerLiteralMatcher.java @@ -34,6 +34,12 @@ public class RustIntegerLiteralMatcher implements org.zwobble.precisely.Matcher< return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteralMatcher(submatchers); } + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteralMatcher withType(org.zwobble.precisely.Matcher<? super java.util.Optional<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIdentifier>> type) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteral>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("type", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteral::type, type)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteralMatcher(submatchers); + } + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteralMatcher body // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteralMatcher body } |
