summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriterTests.java12
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaArrayAccessMatcher.java45
2 files changed, 57 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 f768827..b26b8f5 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
@@ -1075,6 +1075,18 @@ public class JavaWriterTests {
// === Binary operations ===
@Test
+ public void arrayAccess() throws IOException {
+ var java = JavaArrayAccess.arbitrary()
+ .withArrayReference(JavaRef.arbitrary().withName(JavaIdentifier.of("x")))
+ .withIndex(JavaIntegerLiteral.arbitrary().withValue(42))
+ .build();
+
+ var string = write(writer -> writer.writeTopLevelExpression(java));
+
+ assertThat(string, equalTo("x[42]"));
+ }
+
+ @Test
public void binaryOperationAdd() throws IOException {
var java = new JavaBinaryOperation(
JavaBinaryOperator.ADD,
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaArrayAccessMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaArrayAccessMatcher.java
new file mode 100644
index 0000000..1d6887e
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/java/ast/JavaArrayAccessMatcher.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.JavaArrayAccessMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaArrayAccessMatcher imports
+
+public class JavaArrayAccessMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaArrayAccessMatcher isJavaArrayAccess() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaArrayAccessMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaArrayAccess>> submatchers;
+
+ private JavaArrayAccessMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaArrayAccess>> 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.JavaArrayAccess.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaArrayAccessMatcher withArrayReference(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression> arrayReference) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaArrayAccess>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("arrayReference", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaArrayAccess::arrayReference, arrayReference));
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaArrayAccessMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaArrayAccessMatcher withIndex(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaExpression> index) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaArrayAccess>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("index", org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaArrayAccess::index, index));
+ return new org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaArrayAccessMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaArrayAccessMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.java.ast.JavaArrayAccessMatcher body
+}