diff options
Diffstat (limited to 'src/test/java/org/zwobble')
2 files changed, 64 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 1ce78ea..0b5f959 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 @@ -1016,6 +1016,19 @@ public class JavaWriterTests { } @Test + public void ternaryConditional() throws IOException { + var java = new JavaTernaryConditional( + new JavaRef(JavaIdentifier.of("x")), + new JavaRef(JavaIdentifier.of("y")), + new JavaRef(JavaIdentifier.of("z")) + ); + + var string = write(writer -> writer.writeTopLevelExpression(java)); + + assertThat(string, equalTo("x ? y : z")); + } + + @Test public void whenSubExpressionHasLowerPrecedenceThenSubExpressionIsParenthesized() throws IOException { var java = JavaBinaryOperation.arbitrary() .withOperator(JavaBinaryOperator.BITWISE_AND) diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaTernaryConditionalMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaTernaryConditionalMatcher.java new file mode 100644 index 0000000..5f39a26 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaTernaryConditionalMatcher.java @@ -0,0 +1,51 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.java.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditionalMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditionalMatcher imports + +public class JavaTernaryConditionalMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditionalMatcher isJavaTernaryConditional() { + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditionalMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditional>> submatchers; + + private JavaTernaryConditionalMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditional>> 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.JavaTernaryConditional.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditionalMatcher withCondition(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression> condition) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditional>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("condition", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditional::condition, condition)); + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditionalMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditionalMatcher withIfTrue(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression> ifTrue) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditional>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("ifTrue", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditional::ifTrue, ifTrue)); + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditionalMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditionalMatcher withIfFalse(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression> ifFalse) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditional>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("ifFalse", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditional::ifFalse, ifFalse)); + return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditionalMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditionalMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaTernaryConditionalMatcher body +} |
