From 065958bb0bbe55a40a1c3df0748bb0b1625f679f Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 30 Aug 2026 08:50:17 +0100 Subject: Write doc comments for structs --- .../lang/typescript/TypescriptWriterTests.java | 20 ++++++++++++++++++++ .../ast/TypescriptClassDeclarationMatcher.java | 6 ++++++ 2 files changed, 26 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 f034fe0..acb4fea 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 @@ -1,6 +1,7 @@ package org.zwobble.hobgoblin.compiler.output.lang.typescript; import org.junit.jupiter.api.Test; +import org.zwobble.hobgoblin.compiler.ast.DocComment; import org.zwobble.hobgoblin.compiler.output.CodeWriter; import org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.*; @@ -93,6 +94,25 @@ public class TypescriptWriterTests { )); } + @Test + public void classDeclarationWithDocComment() throws IOException { + var typescript = TypescriptClassDeclaration.arbitrary() + .withName(TypescriptIdentifier.of("X")) + .withDocComment(new DocComment("abc\ndef")) + .build(); + + var string = write(writer -> writer.writeStatement(typescript)); + + assertThat(string, equalTo(""" + /** + * abc + * def + */ + class X { + }""" + )); + } + // == Class elements == // === Class field declarations === 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 index ff561bd..46eeaa2 100644 --- 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 @@ -42,6 +42,12 @@ public final class TypescriptClassDeclarationMatcher implements org.zwobble.prec return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclarationMatcher(submatchers); } + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclarationMatcher withDocComment(org.zwobble.precisely.Matcher docComment) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("docComment", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclaration::docComment, (org.zwobble.precisely.Matcher) docComment)); + 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