From 93c7437d22224ac72818a4cd4ed4d9beeedaac79 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 30 Aug 2026 13:43:59 +0100 Subject: Add new calls to TypeScript AST --- .../lang/typescript/TypescriptWriterTests.java | 26 ++++++++++++ .../typescript/ast/TypescriptNewCallMatcher.java | 47 ++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNewCallMatcher.java (limited to 'src/test/java') 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 b0c583f..718f6e4 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 @@ -299,6 +299,32 @@ public class TypescriptWriterTests { assertThat(string, equalTo("x.y")); } + // === New calls === + + @Test + public void newCallWithoutArgs() throws IOException { + var typescript = TypescriptNewCall.arbitrary() + .withReceiver(ref("A")) + .build(); + + var string = write(writer -> writer.writeExpression(typescript)); + + assertThat(string, equalTo("new A()")); + } + + @Test + public void newCallWithArgs() throws IOException { + var typescript = TypescriptNewCall.arbitrary() + .withReceiver(ref("A")) + .addArg(ref("b")) + .addArg(ref("c")) + .build(); + + var string = write(writer -> writer.writeExpression(typescript)); + + assertThat(string, equalTo("new A(b, c)")); + } + // === Number literals === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNewCallMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNewCallMatcher.java new file mode 100644 index 0000000..491b0de --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNewCallMatcher.java @@ -0,0 +1,47 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCallMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCallMatcher imports + +public final class TypescriptNewCallMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCallMatcher isTypescriptNewCall() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCallMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private TypescriptNewCallMatcher( + 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.typescript.ast.TypescriptNewCall.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCallMatcher withReceiver(org.zwobble.precisely.Matcher receiver) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("receiver", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall::receiver, (org.zwobble.precisely.Matcher) receiver)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCallMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCallMatcher withArgs(org.zwobble.precisely.Matcher> args) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("args", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall::args, (org.zwobble.precisely.Matcher) args)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCallMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCallMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCallMatcher body +} -- cgit v1.2.3