diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-05-17 10:30:04 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-05-17 10:30:04 +0100 |
| commit | 9acc7ef12df3f475bbf5f57c0e22d4be16639452 (patch) | |
| tree | 3d99f88d440b75a86340f254655fd840f6307fa0 /src/test/java | |
| parent | f5f84bd0d834d440cc2bf3f38bdee9d6ecf4518b (diff) | |
Add Java return statement node
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java | 50 |
1 files changed, 50 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 b6ad5d5..a19f5a2 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 @@ -243,6 +243,56 @@ public class JavaWriterTests { } @Test + public void methodWithBody() throws IOException { + var java = new JavaMethodDeclaration( + "a", + JavaTypeRef.INT, + List.of(), + new JavaBlock(List.of( + new JavaReturn(new JavaIntegerLiteral(42)) + )) + ); + + var string = write(writer -> writer.writeMethodDeclaration(java)); + + assertThat(string, equalTo(""" + public int a() { + return 42; + }""" + )); + } + + @Test + public void block() throws IOException { + var java = new JavaBlock(List.of( + new JavaReturn(new JavaIntegerLiteral(42)), + new JavaReturn(new JavaIntegerLiteral(47)) + )); + + var string = write(writer -> writer.writeBlock(java)); + + assertThat(string, equalTo("return 42;\nreturn 47;")); + } + + @Test + public void returnStatement() throws IOException { + var java = new JavaReturn(new JavaIntegerLiteral(42)); + + var string = write(writer -> writer.writeBlockStatement(java)); + + assertThat(string, equalTo("return 42;")); + } + + @Test + public void integerLiteral() throws IOException { + var java = new JavaIntegerLiteral(42); + + var string = write(writer -> writer.writeExpression(java)); + + assertThat(string, equalTo("42")); + } + + @Test public void typeRefWithoutArgsHasNoAngleBrackets() throws IOException { var java = new JavaTypeRef(List.of("abc", "def"), "One", List.of()); |
