summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java15
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaLocalVariableDeclarationMatcher.java6
2 files changed, 20 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 75a255a..5b07ecb 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
@@ -780,7 +780,20 @@ public class JavaWriterTests {
}
@Test
- public void localVariableDeclaration() throws IOException {
+ public void localVariableDeclarationUsingExplicitType() throws IOException {
+ var java = JavaLocalVariableDeclaration.arbitrary()
+ .withType(JavaTypeRef.INT)
+ .withName(JavaIdentifier.of("count"))
+ .withInitializer(new JavaIntegerLiteral(42))
+ .build();
+
+ var string = write(writer -> writer.writeBlockStatement(java));
+
+ assertThat(string, equalTo("int count = 42;"));
+ }
+
+ @Test
+ public void localVariableDeclarationUsingVar() throws IOException {
var java = JavaLocalVariableDeclaration.arbitrary()
.withName(JavaIdentifier.of("count"))
.withInitializer(new JavaIntegerLiteral(42))
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 9c2e6ce..d36db60 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
@@ -28,6 +28,12 @@ public class JavaLocalVariableDeclarationMatcher implements org.zwobble.precisel
return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclaration.class, this.submatchers);
}
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclarationMatcher withType(org.zwobble.precisely.Matcher<? super java.util.Optional<org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTypeRef>> type) {
+ 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("type", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclaration::type, type));
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclarationMatcher(submatchers);
+ }
+
public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclarationMatcher withName(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaIdentifier> name) {
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("name", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaLocalVariableDeclaration::name, name));