diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-06-19 18:27:41 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-06-19 18:27:41 +0100 |
| commit | 64344428233e3ed4250477b52f5eb560e168c29b (patch) | |
| tree | 7d2f4e049a798bd91de7da679112a915ca0d1acc /src/test/java | |
| parent | 4a50855f064f0744a0e4b03cb505271880589936 (diff) | |
Add Java enum declarations
Diffstat (limited to 'src/test/java')
3 files changed, 142 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 1de864d..78b975d 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 @@ -174,6 +174,68 @@ public class JavaWriterTests { } @Test + public void emptyEnumDeclaration() throws IOException { + var java = JavaEnumDeclaration.arbitrary() + .withName("SmallNumber") + .withCustomArea(JavaCustomArea.forType(JavaTypeRef.topLevel(List.of(), "SmallNumber"), "body")) + .build(); + + var string = write(writer -> writer.writeTypeDeclaration(java)); + + assertThat(string, equalTo(""" + public enum SmallNumber { + // Custom area start: SmallNumber body + // Custom area end: SmallNumber body + }""" + )); + } + + @Test + public void enumDeclarationWithConstants() throws IOException { + var java = JavaEnumDeclaration.arbitrary() + .withName("SmallNumber") + .withCustomArea(JavaCustomArea.forType(JavaTypeRef.topLevel(List.of(), "SmallNumber"), "body")) + .withConstants(List.of( + JavaEnumConstant.arbitrary().withName("ZERO").build(), + JavaEnumConstant.arbitrary().withName("ONE").build(), + JavaEnumConstant.arbitrary().withName("TWO").build() + )) + .build(); + + var string = write(writer -> writer.writeTypeDeclaration(java)); + + assertThat(string, equalTo(""" + public enum SmallNumber { + ZERO, + ONE, + TWO + + // Custom area start: SmallNumber body + // Custom area end: SmallNumber body + }""" + )); + } + + @Test + public void enumDeclarationWithDocComment() throws IOException { + var java = JavaEnumDeclaration.arbitrary() + .withName("SmallNumber") + .withDocComment(new DocComment("A small number.")) + .withCustomArea(JavaCustomArea.forType(JavaTypeRef.topLevel(List.of(), "SmallNumber"), "body")) + .build(); + + var string = write(writer -> writer.writeTypeDeclaration(java)); + + assertThat(string, equalTo(""" + /// A small number. + public enum SmallNumber { + // Custom area start: SmallNumber body + // Custom area end: SmallNumber body + }""" + )); + } + + @Test public void openInterfaceDeclaration() throws IOException { var java = new JavaInterfaceDeclaration( "Shape", diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaEnumConstantMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaEnumConstantMatcher.java new file mode 100644 index 0000000..58d6f54 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaEnumConstantMatcher.java @@ -0,0 +1,34 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.java.ast; + +public class JavaEnumConstantMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstantMatcher isJavaEnumConstant() { + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstantMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstant>> submatchers; + + private JavaEnumConstantMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstant>> submatchers) { + this.submatchers = submatchers; + } + + public org.zwobble.precisely.MatchResult match(java.lang.Object actual) { + return this.toMatcher().match(actual); + } + + public org.zwobble.precisely.TextTree describe() { + return this.toMatcher().describe(); + } + + private org.zwobble.precisely.Matcher<java.lang.Object> toMatcher() { + return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstant.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstantMatcher withName(org.zwobble.precisely.Matcher<? super String> name) { + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstantMatcher(java.util.stream.Stream.concat(this.submatchers.stream(), java.util.stream.Stream.of(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstant::name, name))).toList()); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstantMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstantMatcher body +} diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaEnumDeclarationMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaEnumDeclarationMatcher.java new file mode 100644 index 0000000..0c7be66 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaEnumDeclarationMatcher.java @@ -0,0 +1,46 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.java.ast; + +public class JavaEnumDeclarationMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclarationMatcher isJavaEnumDeclaration() { + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclarationMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration>> submatchers; + + private JavaEnumDeclarationMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration>> submatchers) { + this.submatchers = submatchers; + } + + public org.zwobble.precisely.MatchResult match(java.lang.Object actual) { + return this.toMatcher().match(actual); + } + + public org.zwobble.precisely.TextTree describe() { + return this.toMatcher().describe(); + } + + private org.zwobble.precisely.Matcher<java.lang.Object> toMatcher() { + return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclarationMatcher withName(org.zwobble.precisely.Matcher<? super String> name) { + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclarationMatcher(java.util.stream.Stream.concat(this.submatchers.stream(), java.util.stream.Stream.of(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration::name, name))).toList()); + } + + public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclarationMatcher withConstants(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumConstant>> constants) { + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclarationMatcher(java.util.stream.Stream.concat(this.submatchers.stream(), java.util.stream.Stream.of(org.zwobble.precisely.Matchers.has("constants", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration::constants, constants))).toList()); + } + + public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclarationMatcher withCustomArea(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaCustomArea> customArea) { + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclarationMatcher(java.util.stream.Stream.concat(this.submatchers.stream(), java.util.stream.Stream.of(org.zwobble.precisely.Matchers.has("customArea", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration::customArea, customArea))).toList()); + } + + public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclarationMatcher withDocComment(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.DocComment> docComment) { + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclarationMatcher(java.util.stream.Stream.concat(this.submatchers.stream(), java.util.stream.Stream.of(org.zwobble.precisely.Matchers.has("docComment", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclaration::docComment, docComment))).toList()); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclarationMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaEnumDeclarationMatcher body +} |
