From 2b887718befc50679896368ae6852335ffff49a6 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 29 Aug 2026 10:15:00 +0100 Subject: Add stubbed TypeScript code writer --- .../lang/typescript/TypescriptWriterTests.java | 46 ++++++++++++++++++++++ .../typescript/ast/TypescriptModuleMatcher.java | 35 ++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModuleMatcher.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 new file mode 100644 index 0000000..8712b4a --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java @@ -0,0 +1,46 @@ +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.TypescriptModule; + +import java.io.IOException; +import java.io.StringWriter; +import java.util.Optional; + +import static org.zwobble.precisely.AssertThat.assertThat; +import static org.zwobble.precisely.Matchers.equalTo; + +public class TypescriptWriterTests { + // == Modules == + + @Test + public void emptyModule() throws IOException { + var typescript = new TypescriptModule(); + + var string = write(writer -> writer.writeModule(typescript)); + + assertThat(string, equalTo(""" + // Generated by hobgoblin. + + """ + )); + } + + private String write(TypescriptWriter.Write write) throws IOException { + return write(write, Optional.empty()); + } + + private String write(TypescriptWriter.Write write, String originalContents) throws IOException { + return write(write, Optional.of(originalContents)); + } + + private String write(TypescriptWriter.Write write, Optional originalContents) throws IOException { + var stringWriter = new StringWriter(); + TypescriptWriter.writeTo( + new CodeWriter.InMemoryCodeWriterFile(originalContents, stringWriter), + write + ); + return stringWriter.toString(); + } +} 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 new file mode 100644 index 0000000..088dba0 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModuleMatcher.java @@ -0,0 +1,35 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher imports + +public final class TypescriptModuleMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher isTypescriptModule() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private TypescriptModuleMatcher( + 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.TypescriptModule.class, this.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