From 9d66911592c3e3f34aaafdd09c7dd9d96e720e18 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 6 Jun 2023 19:42:44 +0100 Subject: Parse call with no effects and no args --- .../compiler/ast/UntypedArgsNodeMatcher.java | 35 +++++++++++++++++++ .../compiler/ast/UntypedCallNodeMatcher.java | 40 ++++++++++++++++++++++ .../shedlang/compiler/ast/UntypedNodeMatchers.java | 8 +++++ 3 files changed, 83 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/ast/UntypedArgsNodeMatcher.java create mode 100644 src/test/java/org/shedlang/compiler/ast/UntypedCallNodeMatcher.java (limited to 'src/test/java/org/shedlang/compiler/ast') diff --git a/src/test/java/org/shedlang/compiler/ast/UntypedArgsNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/UntypedArgsNodeMatcher.java new file mode 100644 index 00000000..315f87d3 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/ast/UntypedArgsNodeMatcher.java @@ -0,0 +1,35 @@ +package org.shedlang.compiler.ast; + +import org.pcollections.PVector; +import org.shedlang.compiler.testing.MatcherBuilder; +import org.zwobble.precisely.Matcher; + +import static org.zwobble.precisely.Matchers.has; + +public class UntypedArgsNodeMatcher extends MatcherBuilder { + public UntypedArgsNodeMatcher() { + super(); + } + + public UntypedArgsNodeMatcher(PVector> submatchers) { + super(submatchers); + } + + @Override + protected Class expectedType() { + return UntypedArgsNode.class; + } + + @Override + protected UntypedArgsNodeMatcher create(PVector> submatchers) { + return new UntypedArgsNodeMatcher(); + } + + public UntypedArgsNodeMatcher withPositional(Matcher> positional) { + return with(has("positional", x -> x.positional(), positional)); + } + + public UntypedArgsNodeMatcher withNamed(Matcher> named) { + return with(has("named", x -> x.named(), named)); + } +} diff --git a/src/test/java/org/shedlang/compiler/ast/UntypedCallNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/UntypedCallNodeMatcher.java new file mode 100644 index 00000000..ef4ad9da --- /dev/null +++ b/src/test/java/org/shedlang/compiler/ast/UntypedCallNodeMatcher.java @@ -0,0 +1,40 @@ +package org.shedlang.compiler.ast; + +import org.pcollections.PVector; +import org.shedlang.compiler.testing.MatcherBuilder; +import org.zwobble.precisely.Matcher; + +import static org.zwobble.precisely.Matchers.equalTo; +import static org.zwobble.precisely.Matchers.has; + +public class UntypedCallNodeMatcher extends MatcherBuilder { + public UntypedCallNodeMatcher() { + super(); + } + + public UntypedCallNodeMatcher(PVector> submatchers) { + super(submatchers); + } + + @Override + protected Class expectedType() { + return UntypedCallNode.class; + } + + @Override + protected UntypedCallNodeMatcher create(PVector> submatchers) { + return new UntypedCallNodeMatcher(); + } + + public UntypedCallNodeMatcher withArgs(Matcher args) { + return with(has("args", x -> x.args(), args)); + } + + public UntypedCallNodeMatcher withHasEffects(boolean hasEffects) { + return with(has("hasEffects", x -> x.hasEffects(), equalTo(hasEffects))); + } + + public UntypedCallNodeMatcher withReceiver(Matcher receiver) { + return with(has("receiver", x -> x.receiver(), receiver)); + } +} diff --git a/src/test/java/org/shedlang/compiler/ast/UntypedNodeMatchers.java b/src/test/java/org/shedlang/compiler/ast/UntypedNodeMatchers.java index 59048782..21e8cf1b 100644 --- a/src/test/java/org/shedlang/compiler/ast/UntypedNodeMatchers.java +++ b/src/test/java/org/shedlang/compiler/ast/UntypedNodeMatchers.java @@ -8,6 +8,14 @@ public class UntypedNodeMatchers { private UntypedNodeMatchers() { } + public static UntypedArgsNodeMatcher isUntypedArgsNode() { + return new UntypedArgsNodeMatcher(); + } + + public static UntypedCallNodeMatcher isUntypedCallNode() { + return new UntypedCallNodeMatcher(); + } + public static Matcher isUntypedReferenceNode(String name) { return instanceOf( UntypedReferenceNode.class, -- cgit v1.2.3