From e97fdb3a32e6c5eaae65d50001a2156ff8752f22 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 29 May 2026 17:03:35 +0100 Subject: Support non-sealed interfaces in Java AST --- .../compiler/output/lang/java/JavaWriterTests.java | 31 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'src/test') 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 a53b20f..c349ec1 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 @@ -94,9 +94,31 @@ public class JavaWriterTests { } @Test - public void emptyInterfaceDeclaration() throws IOException { + public void openInterfaceDeclaration() throws IOException { var java = new JavaInterfaceDeclaration( "Shape", + JavaInterfaceDeclaration.Openness.OPEN, + List.of(), + List.of(), + new JavaCustomArea(JavaTypeRef.topLevel(List.of(), "Shape"), "body"), + DocComment.EMPTY + ); + + var string = write(writer -> writer.writeTypeDeclaration(java)); + + assertThat(string, equalTo(""" + public interface Shape { + // Custom area start: Shape body + // Custom area end: Shape body + }""" + )); + } + + @Test + public void sealedInterfaceDeclaration() throws IOException { + var java = new JavaInterfaceDeclaration( + "Shape", + JavaInterfaceDeclaration.Openness.SEALED, List.of(), List.of(), new JavaCustomArea(JavaTypeRef.topLevel(List.of(), "Shape"), "body"), @@ -117,6 +139,7 @@ public class JavaWriterTests { public void sealedInterfaceDeclarationWithPermitsTypes() throws IOException { var java = new JavaInterfaceDeclaration( "Shape", + JavaInterfaceDeclaration.Openness.SEALED, List.of( JavaTypeRef.topLevel(List.of("abc", "def"), "One"), JavaTypeRef.topLevel(List.of("abc", "def"), "Two") @@ -140,6 +163,7 @@ public class JavaWriterTests { public void interfaceDeclarationWithDocComment() throws IOException { var java = new JavaInterfaceDeclaration( "Shape", + JavaInterfaceDeclaration.Openness.OPEN, List.of(), List.of(), new JavaCustomArea(JavaTypeRef.topLevel(List.of(), "Shape"), "body"), @@ -150,7 +174,7 @@ public class JavaWriterTests { assertThat(string, equalTo(""" /// A 2D shape. - public sealed interface Shape { + public interface Shape { // Custom area start: Shape body // Custom area end: Shape body }""" @@ -161,6 +185,7 @@ public class JavaWriterTests { public void interfaceDeclarationWithBody() throws IOException { var java = new JavaInterfaceDeclaration( "Shape", + JavaInterfaceDeclaration.Openness.OPEN, List.of(), List.of( new JavaMethodDeclaration( @@ -185,7 +210,7 @@ public class JavaWriterTests { var string = write(writer -> writer.writeTypeDeclaration(java)); assertThat(string, equalTo(""" - public sealed interface Shape { + public interface Shape { public static void a() { } -- cgit v1.2.3