diff options
| author | Michael Williamson <mike@zwobble.org> | 2025-01-12 21:41:15 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2025-01-12 21:41:15 +0000 |
| commit | 6b3d2b650c8e6d0dbb35091e279d142db8bedb02 (patch) | |
| tree | 2d00c8c199b4bac5bc4ad29d1b938b61a58caf90 /src/test/java/org/shedlang/compiler/ast | |
| parent | e806ce6188342e3356941b70f11e630b2167b17d (diff) | |
Type check native function declarations
Diffstat (limited to 'src/test/java/org/shedlang/compiler/ast')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/ast/typed/TypedNativeFunctionDeclarationNodeMatcher.java | 59 | ||||
| -rw-r--r-- | src/test/java/org/shedlang/compiler/ast/typed/TypedNodeMatchers.java | 4 |
2 files changed, 63 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/ast/typed/TypedNativeFunctionDeclarationNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/typed/TypedNativeFunctionDeclarationNodeMatcher.java new file mode 100644 index 00000000..94c8c65a --- /dev/null +++ b/src/test/java/org/shedlang/compiler/ast/typed/TypedNativeFunctionDeclarationNodeMatcher.java @@ -0,0 +1,59 @@ +package org.shedlang.compiler.ast.typed; + +import org.pcollections.Empty; +import org.pcollections.PVector; +import org.shedlang.compiler.testing.MatcherBuilder; +import org.shedlang.compiler.types.FunctionType; +import org.zwobble.precisely.Matcher; + +import java.util.Optional; + +import static org.zwobble.precisely.Matchers.*; + +public class TypedNativeFunctionDeclarationNodeMatcher extends MatcherBuilder< + TypedNamespaceStatementNode, + TypedNativeFunctionDeclarationNode, + TypedNativeFunctionDeclarationNodeMatcher +> { + public static TypedNativeFunctionDeclarationNodeMatcher empty() { + return new TypedNativeFunctionDeclarationNodeMatcher(Empty.vector()); + } + + public TypedNativeFunctionDeclarationNodeMatcher( + PVector<Matcher<? super TypedNativeFunctionDeclarationNode>> submatchers + ) { + super(submatchers); + } + + @Override + protected Class<TypedNativeFunctionDeclarationNode> expectedType() { + return TypedNativeFunctionDeclarationNode.class; + } + + @Override + protected TypedNativeFunctionDeclarationNodeMatcher create( + PVector<Matcher<? super TypedNativeFunctionDeclarationNode>> submatchers + ) { + return new TypedNativeFunctionDeclarationNodeMatcher(submatchers); + } + + public TypedNativeFunctionDeclarationNodeMatcher withEffect(Matcher<Optional<? extends TypedTypeLevelExpressionNode<?>>> effect) { + return with(has("effect", x -> x.signature().effect(), effect)); + } + + public TypedNativeFunctionDeclarationNodeMatcher withName(String name) { + return with(has("name", x -> x.name(), equalTo(name))); + } + + public TypedNativeFunctionDeclarationNodeMatcher withParams(Matcher<TypedParamsNode> params) { + return with(has("params", x -> x.signature().params(), params)); + } + + public TypedNativeFunctionDeclarationNodeMatcher withReturnType(Matcher<TypedTypeLevelExpressionNode<?>> returnType) { + return with(has("returnType", x -> x.signature().returnType(), isOptionalOf(returnType))); + } + + public TypedNativeFunctionDeclarationNodeMatcher withType(FunctionType type) { + return with(has("type", x -> x.type(), equalTo(type))); + } +} diff --git a/src/test/java/org/shedlang/compiler/ast/typed/TypedNodeMatchers.java b/src/test/java/org/shedlang/compiler/ast/typed/TypedNodeMatchers.java index 2002577f..902ba59d 100644 --- a/src/test/java/org/shedlang/compiler/ast/typed/TypedNodeMatchers.java +++ b/src/test/java/org/shedlang/compiler/ast/typed/TypedNodeMatchers.java @@ -244,6 +244,10 @@ public class TypedNodeMatchers { return TypedNamespaceNodeMatcher.empty(); } + public static TypedNativeFunctionDeclarationNodeMatcher isTypedNativeFunctionDeclarationNode() { + return TypedNativeFunctionDeclarationNodeMatcher.empty(); + } + public static Matcher<TypedParamNode> isTypedParamNode( String name, Matcher<Optional<? extends TypedTypeLevelExpressionNode<?>>> type |
