diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-08-29 22:52:43 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-08-29 22:52:43 +0100 |
| commit | 9141e8d5a4f22aeaa1c2863c4f7743ce8c35e760 (patch) | |
| tree | 2bb7ccbdd471a56174b236a4e8e338c0542ef374 /src/test | |
| parent | fa0eb2727b12dc38d74228504c49f1a269c32b8c (diff) | |
Add initial value to class field declaration in TypeScript AST
Diffstat (limited to 'src/test')
2 files changed, 18 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 186854c..f034fe0 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 @@ -108,6 +108,18 @@ public class TypescriptWriterTests { assertThat(string, equalTo("a;")); } + @Test + public void classFieldDeclarationWithInitialValue() throws IOException { + var typescript = TypescriptClassFieldDeclaration.arbitrary() + .withName(TypescriptIdentifier.of("a")) + .withInitialValue(TypescriptNumberLiteral.arbitrary().withValue(42)) + .build(); + + var string = write(writer -> writer.writeClassElement(typescript)); + + assertThat(string, equalTo("a = 42.0;")); + } + // == Expressions == // === Number literals === diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassFieldDeclarationMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassFieldDeclarationMatcher.java index 1cbd267..558ad00 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassFieldDeclarationMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassFieldDeclarationMatcher.java @@ -36,6 +36,12 @@ public final class TypescriptClassFieldDeclarationMatcher implements org.zwobble return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclarationMatcher(submatchers); } + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclarationMatcher withInitialValue(org.zwobble.precisely.Matcher<? super java.util.Optional<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression>> initialValue) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclaration>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("initialValue", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclaration::initialValue, (org.zwobble.precisely.Matcher) initialValue)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclarationMatcher(submatchers); + } + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclarationMatcher body // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclarationMatcher body } |
