diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-09-04 09:47:27 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-09-04 09:47:27 +0100 |
| commit | 4bf4004fc90073d816d1431df5bc5845547b814e (patch) | |
| tree | 00fadff43a80381e1e4ab2f63960373f03b8879c /src/test/java | |
| parent | 8dd50423a53f87f15464c467874684300b129ba8 (diff) | |
Add const declaration to TypeScript AST
Diffstat (limited to 'src/test/java')
2 files changed, 80 insertions, 0 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 b45e5c4..5a7c488 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 @@ -133,6 +133,33 @@ public class TypescriptWriterTests { )); } + // === Class declarations === + + @Test + public void constDeclarationWithoutExplicitType() throws IOException { + var typescript = TypescriptConstDeclaration.arbitrary() + .withName(id("x")) + .withValue(num(42)) + .build(); + + var string = write(writer -> writer.writeStatement(typescript)); + + assertThat(string, equalTo("const x = 42.0;")); + } + + @Test + public void constDeclarationWithExplicitType() throws IOException { + var typescript = TypescriptConstDeclaration.arbitrary() + .withName(id("x")) + .withType(ref("number")) + .withValue(num(42)) + .build(); + + var string = write(writer -> writer.writeStatement(typescript)); + + assertThat(string, equalTo("const x: number = 42.0;")); + } + // === Export statements === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptConstDeclarationMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptConstDeclarationMatcher.java new file mode 100644 index 0000000..278d885 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptConstDeclarationMatcher.java @@ -0,0 +1,53 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher imports + +public final class TypescriptConstDeclarationMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher isTypescriptConstDeclaration() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclaration>> submatchers; + + private TypescriptConstDeclarationMatcher( + java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclaration>> 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.TypescriptConstDeclaration.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher withName(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier> name) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclaration>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclaration::name, (org.zwobble.precisely.Matcher) name)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher withType(org.zwobble.precisely.Matcher<? super java.util.Optional<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression>> type) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclaration>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("type", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclaration::type, (org.zwobble.precisely.Matcher) type)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher withValue(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression> value) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclaration>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("value", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclaration::value, (org.zwobble.precisely.Matcher) value)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstDeclarationMatcher body +} |
