From 47eb39b664e9e7565086c2c6f5a79dd1d1b94a86 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 29 Aug 2026 22:23:25 +0100 Subject: Add body to Typescript modules --- .../lang/typescript/TypescriptWriterTests.java | 25 ++++++++++++++++++++++ .../typescript/ast/TypescriptModuleMatcher.java | 6 ++++++ 2 files changed, 31 insertions(+) (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 a5cf539..a375b13 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 @@ -29,6 +29,31 @@ public class TypescriptWriterTests { )); } + @Test + public void moduleWithStatements() throws IOException { + var typescript = TypescriptModule.arbitrary() + .addBodyElement(TypescriptClassDeclaration.arbitrary() + .withName(TypescriptIdentifier.of("X")) + ) + .addBodyElement(TypescriptClassDeclaration.arbitrary() + .withName(TypescriptIdentifier.of("Y")) + ) + .build(); + + var string = write(writer -> writer.writeModule(typescript)); + + assertThat(string, equalTo(""" + // Generated by hobgoblin. + + class X { + } + + class Y { + } + """ + )); + } + // == Statements == // === Class declarations === diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModuleMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModuleMatcher.java index 2a9f2f5..c1bc764 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModuleMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModuleMatcher.java @@ -36,6 +36,12 @@ public final class TypescriptModuleMatcher implements org.zwobble.precisely.Matc return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher(submatchers); } + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher withBody(org.zwobble.precisely.Matcher> body) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("body", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule::body, body)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher(submatchers); + } + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher body // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher body } -- cgit v1.2.3