summaryrefslogtreecommitdiff
path: root/src/test/java/org
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-06-12 15:43:02 +0100
committerMichael Williamson <mike@zwobble.org>2026-06-12 15:43:02 +0100
commitdeee2d3f92e3f09b711e1fc68a25129bc554df2a (patch)
tree71319a012b885f33430e81628881986617bd6efd /src/test/java/org
parent4455f5d14c3f80d13758f10e726e422d183b5f31 (diff)
Add implementsTypes to JavaClassDeclaration
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java96
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",