summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-07-12 17:43:27 +0100
committerMichael Williamson <mike@zwobble.org>2026-07-12 17:43:27 +0100
commita8f916ed81731eaba61b2bd1ef6f3b6fb40c23af (patch)
tree19c773b72a1bd22b0065f8d0780d81eb5b129b79 /src/test/java
parented2fc42b45faa1392342ca7c62e4ad580091bf60 (diff)
Add postfix expressions to Java AST
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java26
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaPostfixExpressionMatcher.java45
2 files changed, 71 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 b8bfe5c..8eb738a 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
@@ -1372,6 +1372,32 @@ public class JavaWriterTests {
assertThat(string, equalTo("null"));
}
+ // === Postfix expressions ===
+
+ @Test
+ public void postfixDecrement() throws IOException {
+ var java = JavaPostfixExpression.arbitrary()
+ .withOperator(JavaPostfixOperator.DECREMENT)
+ .withOperand(JavaRef.arbitrary().withName(JavaIdentifier.of("x")))
+ .build();
+
+ var string = write(writer -> writer.writeTopLevelExpression(java));
+
+ assertThat(string, equalTo("x--"));
+ }
+
+ @Test
+ public void postfixIncrement() throws IOException {
+ var java = JavaPostfixExpression.arbitrary()
+ .withOperator(JavaPostfixOperator.INCREMENT)
+ .withOperand(JavaRef.arbitrary().withName(JavaIdentifier.of("x")))
+ .build();
+
+ var string = write(writer -> writer.writeTopLevelExpression(java));
+
+ assertThat(string, equalTo("x++"));
+ }
+
// === Refs ===
@Test
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaPostfixExpressionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaPostfixExpressionMatcher.java
new file mode 100644
index 0000000..2a0cb13
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaPostfixExpressionMatcher.java
@@ -0,0 +1,45 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.java.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher imports
+
+public class JavaPostfixExpressionMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher isJavaPostfixExpression() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpression>> submatchers;
+
+ private JavaPostfixExpressionMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpression>> 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.JavaPostfixExpression.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher withOperator(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixOperator> operator) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpression>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("operator", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpression::operator, operator));
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher withOperand(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression> operand) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpression>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("operand", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpression::operand, operand));
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaPostfixExpressionMatcher body
+}