summaryrefslogtreecommitdiff
path: root/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java28
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaRecordDeclarationMatcher.java6
2 files changed, 34 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 75a57a6..e8556bc 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
@@ -395,6 +395,7 @@ public class JavaWriterTests {
List.of(),
List.of(),
List.of(),
+ List.of(),
DocComment.EMPTY
);
@@ -415,6 +416,7 @@ public class JavaWriterTests {
List.of(),
List.of(),
List.of(),
+ List.of(),
new DocComment("A 2D point.")
);
@@ -430,10 +432,33 @@ public class JavaWriterTests {
}
@Test
+ public void recordDeclarationWithTypeParams() throws IOException {
+ var java = JavaRecordDeclaration.arbitrary()
+ .withType(JavaTypeRef.topLevel(JavaPackageName.EMPTY, JavaIdentifier.of("X")))
+ .addTypeParameter(JavaTypeParameter.arbitrary()
+ .withName(JavaIdentifier.of("T1"))
+ )
+ .addTypeParameter(JavaTypeParameter.arbitrary()
+ .withName(JavaIdentifier.of("T2"))
+ )
+ .build();
+
+ var string = write(writer -> writer.writeTypeDeclaration(java));
+
+ assertThat(string, equalTo("""
+ public record X<T1, T2>() {
+ // Custom area start: X body
+ // Custom area end: X body
+ }"""
+ ));
+ }
+
+ @Test
public void recordDeclarationImplementingOneInterface() throws IOException {
var java = new JavaRecordDeclaration(
JavaTypeRef.topLevel(JavaPackageName.EMPTY, JavaIdentifier.of("Rectangle")),
List.of(),
+ List.of(),
List.of(
JavaTypeRef.topLevel(JavaPackageName.of("com", "example"), JavaIdentifier.of("Shape"))
),
@@ -456,6 +481,7 @@ public class JavaWriterTests {
var java = new JavaRecordDeclaration(
JavaTypeRef.topLevel(JavaPackageName.EMPTY, JavaIdentifier.of("Rectangle")),
List.of(),
+ List.of(),
List.of(
JavaTypeRef.topLevel(JavaPackageName.of("com", "example"), JavaIdentifier.of("Shape")),
JavaTypeRef.topLevel(JavaPackageName.of("com", "example"), JavaIdentifier.of("Drawable"))
@@ -480,6 +506,7 @@ public class JavaWriterTests {
JavaTypeRef.topLevel(JavaPackageName.EMPTY, JavaIdentifier.of("Rectangle")),
List.of(),
List.of(),
+ List.of(),
List.of(
JavaMethodDeclaration.arbitrary()
.withName(JavaIdentifier.of("a"))
@@ -1851,6 +1878,7 @@ public class JavaWriterTests {
List.of(),
List.of(),
List.of(),
+ List.of(),
DocComment.EMPTY
);
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaRecordDeclarationMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaRecordDeclarationMatcher.java
index 56ac030..8661a62 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaRecordDeclarationMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaRecordDeclarationMatcher.java
@@ -36,6 +36,12 @@ public final class JavaRecordDeclarationMatcher implements org.zwobble.precisely
return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordDeclarationMatcher(submatchers);
}
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordDeclarationMatcher withTypeParameters(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTypeParameter>> typeParameters) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordDeclaration>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("typeParameters", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordDeclaration::typeParameters, typeParameters));
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordDeclarationMatcher(submatchers);
+ }
+
public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordDeclarationMatcher withComponents(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordComponent>> components) {
var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordDeclaration>>(this.submatchers);
submatchers.add(org.zwobble.precisely.Matchers.has("components", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaRecordDeclaration::components, components));