diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-10-22 22:23:01 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-10-22 22:23:01 +0100 |
| commit | d1d0984bc8a157a2f001d3c991dae5c9498cd790 (patch) | |
| tree | 89056dc50059c60c4ce1bf9aa18a8045fb282036 /src/test/java/org/shedlang/compiler/ast | |
| parent | bc94a020433c8b7dc0adaa2a6adf235da9c9b4e9 (diff) | |
Parse function types
Diffstat (limited to 'src/test/java/org/shedlang/compiler/ast')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/ast/untyped/UntypedFunctionTypeNodeMatcher.java | 48 | ||||
| -rw-r--r-- | src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java | 14 |
2 files changed, 62 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedFunctionTypeNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedFunctionTypeNodeMatcher.java new file mode 100644 index 00000000..166dd1b0 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedFunctionTypeNodeMatcher.java @@ -0,0 +1,48 @@ +package org.shedlang.compiler.ast.untyped; + +import org.pcollections.Empty; +import org.pcollections.PVector; +import org.shedlang.compiler.testing.MatcherBuilder; +import org.zwobble.precisely.Matcher; + +import java.util.Optional; + +import static org.zwobble.precisely.Matchers.has; + +public class UntypedFunctionTypeNodeMatcher extends MatcherBuilder< + UntypedTypeLevelExpressionNode, + UntypedFunctionTypeNode, + UntypedFunctionTypeNodeMatcher +> { + public static UntypedFunctionTypeNodeMatcher empty() { + return new UntypedFunctionTypeNodeMatcher(Empty.vector()); + } + + public UntypedFunctionTypeNodeMatcher(PVector<Matcher<? super UntypedFunctionTypeNode>> submatchers) { + super(submatchers); + } + + @Override + protected Class<UntypedFunctionTypeNode> expectedType() { + return UntypedFunctionTypeNode.class; + } + + @Override + protected UntypedFunctionTypeNodeMatcher create( + PVector<Matcher<? super UntypedFunctionTypeNode>> submatchers + ) { + return new UntypedFunctionTypeNodeMatcher(submatchers); + } + + public UntypedFunctionTypeNodeMatcher withEffect(Matcher<Optional<? extends UntypedTypeLevelExpressionNode>> effect) { + return with(has("effect", x -> x.effect(), effect)); + } + + public UntypedFunctionTypeNodeMatcher withParams(Matcher<UntypedParamTypesNode> params) { + return with(has("params", x -> x.params(), params)); + } + + public UntypedFunctionTypeNodeMatcher withReturnType(Matcher<UntypedTypeLevelExpressionNode> returnType) { + return with(has("returnType", x -> x.returnType(), returnType)); + } +} diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java index 35e8247a..f45adba9 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java @@ -123,6 +123,10 @@ public class UntypedNodeMatchers { ); } + public static UntypedFunctionTypeNodeMatcher isUntypedFunctionTypeNode() { + return UntypedFunctionTypeNodeMatcher.empty(); + } + public static Matcher<UntypedExpressionNode> isUntypedIfNode( Matcher<Iterable<? extends UntypedConditionalBranchNode>> conditionalBranches, Matcher<UntypedBlockNode> elseBody @@ -188,6 +192,16 @@ public class UntypedNodeMatchers { ); } + public static Matcher<UntypedParamTypesNode> isUntypedParamTypesNode( + Matcher<Iterable<? extends UntypedTypeLevelExpressionNode>> positional, + Matcher<Iterable<? extends UntypedParamNode>> named + ) { + return allOf( + has("positional", x -> x.positional(), positional), + has("named", x -> x.named(), named) + ); + } + public static Matcher<UntypedExpressionNode> isUntypedReferenceNode(String name) { return instanceOf( UntypedReferenceNode.class, |
