diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-08-29 22:46:39 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-08-29 22:46:39 +0100 |
| commit | fa0eb2727b12dc38d74228504c49f1a269c32b8c (patch) | |
| tree | 95cab36909903f3bf0d5f8a47bb42484073a0042 /src/test/java | |
| parent | d975ac0ba736e373c78661950b2884d12ac2a416 (diff) | |
Add number literals to TypeScript AST
Diffstat (limited to 'src/test/java')
2 files changed, 57 insertions, 4 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java index 05fa013..186854c 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java @@ -2,10 +2,7 @@ package org.zwobble.hobgoblin.compiler.output.lang.typescript; import org.junit.jupiter.api.Test; import org.zwobble.hobgoblin.compiler.output.CodeWriter; -import org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclaration; -import org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclaration; -import org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier; -import org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule; +import org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.*; import java.io.IOException; import java.io.StringWriter; @@ -111,6 +108,21 @@ public class TypescriptWriterTests { assertThat(string, equalTo("a;")); } + // == Expressions == + + // === Number literals === + + @Test + public void numberLiteral() throws IOException { + var typescript = TypescriptNumberLiteral.arbitrary() + .withValue(42) + .build(); + + var string = write(writer -> writer.writeExpression(typescript)); + + assertThat(string, equalTo("42.0")); + } + private String write(TypescriptWriter.Write write) throws IOException { return write(write, Optional.empty()); } diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNumberLiteralMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNumberLiteralMatcher.java new file mode 100644 index 0000000..0fe555a --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNumberLiteralMatcher.java @@ -0,0 +1,41 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteralMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteralMatcher imports + +public final class TypescriptNumberLiteralMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteralMatcher isTypescriptNumberLiteral() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteralMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral>> submatchers; + + private TypescriptNumberLiteralMatcher( + java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral>> 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.typescript.ast.TypescriptNumberLiteral.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteralMatcher withValue(org.zwobble.precisely.Matcher<? super java.lang.Double> value) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("value", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral::value, (org.zwobble.precisely.Matcher) value)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteralMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteralMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteralMatcher body +} |
