From bd664e8cffcaf997631c9a8f5a5770d5a8bbe4d7 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 29 Aug 2026 22:19:10 +0100 Subject: Add class declarations to TypeScript AST --- .../lang/typescript/TypescriptWriterTests.java | 20 +++++++++++ .../ast/TypescriptClassDeclarationMatcher.java | 41 ++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassDeclarationMatcher.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 71978f0..a5cf539 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 @@ -2,6 +2,8 @@ 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.TypescriptClassDeclaration; +import org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier; import org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule; import java.io.IOException; @@ -27,6 +29,24 @@ public class TypescriptWriterTests { )); } + // == Statements == + + // === Class declarations === + + @Test + public void emptyClassDeclaration() throws IOException { + var typescript = TypescriptClassDeclaration.arbitrary() + .withName(TypescriptIdentifier.of("X")) + .build(); + + var string = write(writer -> writer.writeStatement(typescript)); + + assertThat(string, equalTo(""" + class X { + }""" + )); + } + private String write(TypescriptWriter.Write write) throws IOException { return write(write, Optional.empty()); } diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassDeclarationMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassDeclarationMatcher.java new file mode 100644 index 0000000..8bde6e1 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassDeclarationMatcher.java @@ -0,0 +1,41 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclarationMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclarationMatcher imports + +public final class TypescriptClassDeclarationMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclarationMatcher isTypescriptClassDeclaration() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclarationMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private TypescriptClassDeclarationMatcher( + 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.TypescriptClassDeclaration.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclarationMatcher withName(org.zwobble.precisely.Matcher name) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclaration::name, name)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclarationMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclarationMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclarationMatcher body +} -- cgit v1.2.3