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.java25
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaLocalVariableDeclarationMatcher.java2
2 files changed, 26 insertions, 1 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 508321e..f768827 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
@@ -1034,6 +1034,31 @@ public class JavaWriterTests {
assertThat(string, equalTo("var count = 42;"));
}
+ @Test
+ public void localVariableDeclarationWithInitializer() throws IOException {
+ var java = JavaLocalVariableDeclaration.arbitrary()
+ .withName(JavaIdentifier.of("count"))
+ .withInitializer(new JavaIntegerLiteral(42))
+ .build();
+
+ var string = write(writer -> writer.writeBlockStatement(java));
+
+ assertThat(string, equalTo("var count = 42;"));
+ }
+
+ @Test
+ public void localVariableDeclarationWithoutInitializer() throws IOException {
+ var java = JavaLocalVariableDeclaration.arbitrary()
+ .withType(JavaTypeRef.INT)
+ .withName(JavaIdentifier.of("count"))
+ .withInitializer(Optional.empty())
+ .build();
+
+ var string = write(writer -> writer.writeBlockStatement(java));
+
+ assertThat(string, equalTo("int count;"));
+ }
+
// === Returns ===
@Test
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaLocalVariableDeclarationMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaLocalVariableDeclarationMatcher.java
index d36db60..a39fcd2 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaLocalVariableDeclarationMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaLocalVariableDeclarationMatcher.java
@@ -40,7 +40,7 @@ public class JavaLocalVariableDeclarationMatcher implements org.zwobble.precisel
return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclarationMatcher(submatchers);
}
- public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclarationMatcher withInitializer(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression> initializer) {
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclarationMatcher withInitializer(org.zwobble.precisely.Matcher<? super java.util.Optional<org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression>> initializer) {
var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclaration>>(this.submatchers);
submatchers.add(org.zwobble.precisely.Matchers.has("initializer", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclaration::initializer, initializer));
return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclarationMatcher(submatchers);