diff options
Diffstat (limited to 'src/test/java/org')
| -rw-r--r-- | src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java | 82 |
1 files changed, 42 insertions, 40 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 8b60341..80c145d 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 @@ -1267,7 +1267,7 @@ public class JavaWriterTests { // == Expressions == - // === Binary operations === + // === Array accesses === @Test public void arrayAccess() throws IOException { @@ -1281,6 +1281,8 @@ public class JavaWriterTests { assertThat(string, equalTo("x[42]")); } + // === Binary operations === + @Test public void binaryOperationAdd() throws IOException { var java = new JavaBinaryOperation( @@ -1308,6 +1310,32 @@ public class JavaWriterTests { } @Test + public void binaryOperationBitwiseAnd() throws IOException { + var java = JavaBinaryOperation.arbitrary() + .withOperator(JavaBinaryOperator.BITWISE_AND) + .withLeft(JavaRef.arbitrary().withName(JavaIdentifier.of("x"))) + .withRight(JavaRef.arbitrary().withName(JavaIdentifier.of("y"))) + .build(); + + var string = write(writer -> writer.writeTopLevelExpression(java)); + + assertThat(string, equalTo("x & y")); + } + + @Test + public void binaryOperationBitwiseOr() throws IOException { + var java = JavaBinaryOperation.arbitrary() + .withOperator(JavaBinaryOperator.BITWISE_OR) + .withLeft(JavaRef.arbitrary().withName(JavaIdentifier.of("x"))) + .withRight(JavaRef.arbitrary().withName(JavaIdentifier.of("y"))) + .build(); + + var string = write(writer -> writer.writeTopLevelExpression(java)); + + assertThat(string, equalTo("x | y")); + } + + @Test public void binaryOperationEqualTo() throws IOException { var java = new JavaBinaryOperation( JavaBinaryOperator.EQUAL_TO, @@ -1321,6 +1349,19 @@ public class JavaWriterTests { } @Test + public void binaryOperationLeftShift() throws IOException { + var java = JavaBinaryOperation.arbitrary() + .withOperator(JavaBinaryOperator.LEFT_SHIFT) + .withLeft(JavaRef.arbitrary().withName(JavaIdentifier.of("x"))) + .withRight(JavaRef.arbitrary().withName(JavaIdentifier.of("y"))) + .build(); + + var string = write(writer -> writer.writeTopLevelExpression(java)); + + assertThat(string, equalTo("x << y")); + } + + @Test public void binaryOperationLessThan() throws IOException { var java = new JavaBinaryOperation( JavaBinaryOperator.LESS_THAN, @@ -1360,19 +1401,6 @@ public class JavaWriterTests { } @Test - public void binaryOperationUnsignedLeftShift() throws IOException { - var java = JavaBinaryOperation.arbitrary() - .withOperator(JavaBinaryOperator.LEFT_SHIFT) - .withLeft(JavaRef.arbitrary().withName(JavaIdentifier.of("x"))) - .withRight(JavaRef.arbitrary().withName(JavaIdentifier.of("y"))) - .build(); - - var string = write(writer -> writer.writeTopLevelExpression(java)); - - assertThat(string, equalTo("x << y")); - } - - @Test public void binaryOperationUnsignedRightShift() throws IOException { var java = JavaBinaryOperation.arbitrary() .withOperator(JavaBinaryOperator.UNSIGNED_RIGHT_SHIFT) @@ -1385,32 +1413,6 @@ public class JavaWriterTests { assertThat(string, equalTo("x >>> y")); } - @Test - public void binaryOperationBitwiseAnd() throws IOException { - var java = JavaBinaryOperation.arbitrary() - .withOperator(JavaBinaryOperator.BITWISE_AND) - .withLeft(JavaRef.arbitrary().withName(JavaIdentifier.of("x"))) - .withRight(JavaRef.arbitrary().withName(JavaIdentifier.of("y"))) - .build(); - - var string = write(writer -> writer.writeTopLevelExpression(java)); - - assertThat(string, equalTo("x & y")); - } - - @Test - public void binaryOperationBitwiseOr() throws IOException { - var java = JavaBinaryOperation.arbitrary() - .withOperator(JavaBinaryOperator.BITWISE_OR) - .withLeft(JavaRef.arbitrary().withName(JavaIdentifier.of("x"))) - .withRight(JavaRef.arbitrary().withName(JavaIdentifier.of("y"))) - .build(); - - var string = write(writer -> writer.writeTopLevelExpression(java)); - - assertThat(string, equalTo("x | y")); - } - // === Boolean literals === @Test |
