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 --- .../shedlang/compiler/testing/MatcherBuilder.java | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/testing/MatcherBuilder.java (limited to 'src/test/java/org/shedlang/compiler/testing') diff --git a/src/test/java/org/shedlang/compiler/testing/MatcherBuilder.java b/src/test/java/org/shedlang/compiler/testing/MatcherBuilder.java new file mode 100644 index 00000000..6736659f --- /dev/null +++ b/src/test/java/org/shedlang/compiler/testing/MatcherBuilder.java @@ -0,0 +1,42 @@ +package org.shedlang.compiler.testing; + +import org.pcollections.Empty; +import org.pcollections.PVector; +import org.zwobble.precisely.MatchResult; +import org.zwobble.precisely.Matcher; +import org.zwobble.precisely.TextTree; + +import static org.zwobble.precisely.Matchers.instanceOf; + +public abstract class MatcherBuilder implements Matcher { + private final PVector> submatchers; + + public MatcherBuilder() { + this(Empty.vector()); + } + + public MatcherBuilder(PVector> submatchers) { + this.submatchers = submatchers; + } + + @Override + public MatchResult match(T actual) { + return toMatcher().match(actual); + } + + @Override + public TextTree describe() { + return toMatcher().describe(); + } + + protected abstract Class expectedType(); + protected abstract This create(PVector> submatchers); + + protected This with(Matcher submatcher) { + return create(submatchers.plus(submatcher)); + } + + private Matcher toMatcher() { + return instanceOf(expectedType(), submatchers); + } +} -- cgit v1.2.3