From 679f041d110605e7797795cd42ae6914193b9d88 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 17 May 2026 10:08:19 +0100 Subject: Add body to Java record node --- .../compiler/output/lang/java/JavaWriterTests.java | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/test/java') 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 a6f7e45..0d36bcb 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 @@ -134,6 +134,7 @@ public class JavaWriterTests { "Point", List.of(), List.of(), + List.of(), DocComment.EMPTY ); @@ -151,6 +152,7 @@ public class JavaWriterTests { "Point", List.of(), List.of(), + List.of(), new DocComment("A 2D point.") ); @@ -163,6 +165,38 @@ public class JavaWriterTests { )); } + @Test + public void recordDeclarationWithMethods() throws IOException { + var java = new JavaRecordDeclaration( + "Rectangle", + List.of(), + List.of(), + List.of( + new JavaMethodDeclaration( + "a", + JavaTypeRef.VOID + ), + new JavaMethodDeclaration( + "b", + JavaTypeRef.VOID + ) + ), + DocComment.EMPTY + ); + + var string = write(writer -> writer.writeTypeDeclaration(java)); + + assertThat(string, equalTo(""" + public record Rectangle() { + public void a() { + } + + public void b() { + } + }""" + )); + } + @Test public void typeRefWithoutArgsHasNoAngleBrackets() throws IOException { var java = new JavaTypeRef(List.of("abc", "def"), "One", List.of()); -- cgit v1.2.3