From 1cc30d7d45377b98ee754e248149bf2f0cc485fb Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 23 May 2026 11:33:47 +0100 Subject: Write custom area content --- .../compiler/output/lang/java/JavaWriterTests.java | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'src/test/java/org') diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java index 5595b62..e13c3dd 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java @@ -72,6 +72,26 @@ public class JavaWriterTests { )); } + @Test + public void classDeclarationWithCustomArea() throws IOException { + var java = new JavaClassDeclaration( + "Point", + List.of(), + new JavaCustomArea(List.of("// ")), + DocComment.EMPTY + ); + + var string = write(writer -> writer.writeTypeDeclaration(java)); + + assertThat(string, equalTo(""" + public class Point { + // Custom area start: body + // + // Custom area end: body + }""" + )); + } + @Test public void classDeclarationWithDocComment() throws IOException { var java = new JavaClassDeclaration( @@ -133,6 +153,26 @@ public class JavaWriterTests { )); } + @Test + public void interfaceDeclarationWithCustomArea() throws IOException { + var java = new JavaInterfaceDeclaration( + "Shape", + List.of(), + new JavaCustomArea(List.of("// ")), + DocComment.EMPTY + ); + + var string = write(writer -> writer.writeTypeDeclaration(java)); + + assertThat(string, equalTo(""" + public sealed interface Shape { + // Custom area start: body + // + // Custom area end: body + }""" + )); + } + @Test public void interfaceDeclarationWithDocComment() throws IOException { var java = new JavaInterfaceDeclaration( @@ -174,6 +214,28 @@ public class JavaWriterTests { )); } + @Test + public void recordDeclarationWithCustomArea() throws IOException { + var java = new JavaRecordDeclaration( + "Point", + List.of(), + List.of(), + List.of(), + new JavaCustomArea(List.of("// ")), + DocComment.EMPTY + ); + + var string = write(writer -> writer.writeTypeDeclaration(java)); + + assertThat(string, equalTo(""" + public record Point() { + // Custom area start: body + // + // Custom area end: body + }""" + )); + } + @Test public void recordDeclarationWithDocComment() throws IOException { var java = new JavaRecordDeclaration( -- cgit v1.2.3