diff options
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java | 96 |
1 files changed, 96 insertions, 0 deletions
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 798de28..53a3e65 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 @@ -23,6 +23,7 @@ public class JavaWriterTests { new JavaClassDeclaration( "Rectangle", List.of(), + List.of(), new JavaCustomArea(JavaTypeRef.topLevel(List.of(), "Rectangle"), "body"), DocComment.EMPTY ) @@ -48,6 +49,7 @@ public class JavaWriterTests { var java = new JavaClassDeclaration( "Rectangle", List.of(), + List.of(), new JavaCustomArea(JavaTypeRef.topLevel(List.of(), "Rectangle"), "body"), DocComment.EMPTY ); @@ -63,9 +65,55 @@ public class JavaWriterTests { } @Test + public void classDeclarationImplementingSingleInterface() throws IOException { + var java = new JavaClassDeclaration( + "Rectangle", + List.of( + JavaTypeRef.topLevel(List.of("com.example"), "Shape") + ), + List.of(), + new JavaCustomArea(JavaTypeRef.topLevel(List.of(), "Rectangle"), "body"), + DocComment.EMPTY + ); + + var string = write(writer -> writer.writeTypeDeclaration(java)); + + assertThat(string, equalTo(""" + public class Rectangle implements com.example.Shape { + // Custom area start: Rectangle body + // Custom area end: Rectangle body + }""" + )); + } + + @Test + public void classDeclarationImplementingMultipleInterfaces() throws IOException { + var java = new JavaClassDeclaration( + "Rectangle", + List.of( + JavaTypeRef.topLevel(List.of("com.example"), "Shape"), + JavaTypeRef.topLevel(List.of("com.example"), "Drawable") + ), + List.of(), + new JavaCustomArea(JavaTypeRef.topLevel(List.of(), "Rectangle"), "body"), + DocComment.EMPTY + ); + + var string = write(writer -> writer.writeTypeDeclaration(java)); + + assertThat(string, equalTo(""" + public class Rectangle implements com.example.Shape, com.example.Drawable { + // Custom area start: Rectangle body + // Custom area end: Rectangle body + }""" + )); + } + + @Test public void classDeclarationWithMethods() throws IOException { var java = new JavaClassDeclaration( "Rectangle", + List.of(), List.of( new JavaMethodDeclaration( "a", @@ -107,6 +155,7 @@ public class JavaWriterTests { var java = new JavaClassDeclaration( "Point", List.of(), + List.of(), new JavaCustomArea(JavaTypeRef.topLevel(List.of(), "Point"), "body"), new DocComment("A 2D point.") ); @@ -296,6 +345,53 @@ public class JavaWriterTests { } @Test + public void recordDeclarationImplementingOneInterface() throws IOException { + var java = new JavaRecordDeclaration( + "Rectangle", + List.of(), + List.of( + JavaTypeRef.topLevel(List.of("com.example"), "Shape") + ), + List.of(), + new JavaCustomArea(JavaTypeRef.topLevel(List.of(), "Rectangle"), "body"), + DocComment.EMPTY + ); + + var string = write(writer -> writer.writeTypeDeclaration(java)); + + assertThat(string, equalTo(""" + public record Rectangle() implements com.example.Shape { + // Custom area start: Rectangle body + // Custom area end: Rectangle body + }""" + )); + } + + @Test + public void recordDeclarationImplementingMultipleInterfaces() throws IOException { + var java = new JavaRecordDeclaration( + "Rectangle", + List.of(), + List.of( + JavaTypeRef.topLevel(List.of("com.example"), "Shape"), + JavaTypeRef.topLevel(List.of("com.example"), "Drawable") + ), + List.of(), + new JavaCustomArea(JavaTypeRef.topLevel(List.of(), "Rectangle"), "body"), + DocComment.EMPTY + ); + + var string = write(writer -> writer.writeTypeDeclaration(java)); + + assertThat(string, equalTo(""" + public record Rectangle() implements com.example.Shape, com.example.Drawable { + // Custom area start: Rectangle body + // Custom area end: Rectangle body + }""" + )); + } + + @Test public void recordDeclarationWithMethods() throws IOException { var java = new JavaRecordDeclaration( "Rectangle", |
