diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-06-06 19:42:44 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-06-06 19:42:44 +0100 |
| commit | 9d66911592c3e3f34aaafdd09c7dd9d96e720e18 (patch) | |
| tree | 0e033546c49d221163f85d60f52f608a8b8f137e /src/test/java/org/shedlang/compiler/testing | |
| parent | 7c358460db1c42a5b7e79b7c6706ebf2adcff39f (diff) | |
Parse call with no effects and no args
Diffstat (limited to 'src/test/java/org/shedlang/compiler/testing')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/testing/MatcherBuilder.java | 42 |
1 files changed, 42 insertions, 0 deletions
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<T, U, This> implements Matcher<T> { + private final PVector<Matcher<? super U>> submatchers; + + public MatcherBuilder() { + this(Empty.vector()); + } + + public MatcherBuilder(PVector<Matcher<? super U>> submatchers) { + this.submatchers = submatchers; + } + + @Override + public MatchResult match(T actual) { + return toMatcher().match(actual); + } + + @Override + public TextTree describe() { + return toMatcher().describe(); + } + + protected abstract Class<U> expectedType(); + protected abstract This create(PVector<Matcher<? super U>> submatchers); + + protected This with(Matcher<? super U> submatcher) { + return create(submatchers.plus(submatcher)); + } + + private Matcher<T> toMatcher() { + return instanceOf(expectedType(), submatchers); + } +} |
