From 1353fdb3257c2a6c249b4bb11b0f13f382c22459 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 29 Oct 2023 20:30:37 +0000 Subject: Add separate type for named params in function type --- .../untyped/UntypedFunctionTypeNodeMatcher.java | 2 +- .../compiler/ast/untyped/UntypedNodeMatchers.java | 30 ++++++++++++++-------- .../compiler/parser/ParserFunctionTypeTests.java | 24 ++++++++--------- 3 files changed, 33 insertions(+), 23 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedFunctionTypeNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedFunctionTypeNodeMatcher.java index 166dd1b0..eb13ced4 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedFunctionTypeNodeMatcher.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedFunctionTypeNodeMatcher.java @@ -38,7 +38,7 @@ public class UntypedFunctionTypeNodeMatcher extends MatcherBuilder< return with(has("effect", x -> x.effect(), effect)); } - public UntypedFunctionTypeNodeMatcher withParams(Matcher params) { + public UntypedFunctionTypeNodeMatcher withParams(Matcher params) { return with(has("params", x -> x.params(), params)); } 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 1a7f0611..db788968 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java @@ -135,6 +135,26 @@ public class UntypedNodeMatchers { return UntypedFunctionTypeNodeMatcher.empty(); } + public static Matcher isUntypedFunctionTypeParamsNode( + Matcher> positional, + Matcher> named + ) { + return allOf( + has("positional", x -> x.positional(), positional), + has("named", x -> x.named(), named) + ); + } + + public static Matcher isUntypedFunctionTypeNamedParamNode( + String name, + Matcher type + ) { + return allOf( + has("name", x -> x.name(), equalTo(name)), + has("type", x -> x.type(), type) + ); + } + public static Matcher isUntypedIfNode( Matcher> conditionalBranches, Matcher elseBody @@ -200,16 +220,6 @@ public class UntypedNodeMatchers { ); } - public static Matcher isUntypedParamTypesNode( - Matcher> positional, - Matcher> named - ) { - return allOf( - has("positional", x -> x.positional(), positional), - has("named", x -> x.named(), named) - ); - } - public static Matcher isUntypedReferenceNode(String name) { return instanceOf( UntypedReferenceNode.class, diff --git a/src/test/java/org/shedlang/compiler/parser/ParserFunctionTypeTests.java b/src/test/java/org/shedlang/compiler/parser/ParserFunctionTypeTests.java index 76311a97..209220ad 100644 --- a/src/test/java/org/shedlang/compiler/parser/ParserFunctionTypeTests.java +++ b/src/test/java/org/shedlang/compiler/parser/ParserFunctionTypeTests.java @@ -19,7 +19,7 @@ public class ParserFunctionTypeTests { assertThat( node, isUntypedFunctionTypeNode() - .withParams(isUntypedParamTypesNode( + .withParams(isUntypedFunctionTypeParamsNode( isSequence(), isSequence() )) @@ -37,7 +37,7 @@ public class ParserFunctionTypeTests { assertThat( node, isUntypedFunctionTypeNode() - .withParams(isUntypedParamTypesNode( + .withParams(isUntypedFunctionTypeParamsNode( isSequence( isUntypedTypeLevelReferenceNode("Int") ), @@ -55,7 +55,7 @@ public class ParserFunctionTypeTests { assertThat( node, isUntypedFunctionTypeNode() - .withParams(isUntypedParamTypesNode( + .withParams(isUntypedFunctionTypeParamsNode( isSequence( isUntypedTypeLevelReferenceNode("Int"), isUntypedTypeLevelReferenceNode("String"), @@ -75,10 +75,10 @@ public class ParserFunctionTypeTests { assertThat( node, isUntypedFunctionTypeNode() - .withParams(isUntypedParamTypesNode( + .withParams(isUntypedFunctionTypeParamsNode( isSequence(), isSequence( - isUntypedParamNode("a", isUntypedTypeLevelReferenceNode("Int")) + isUntypedFunctionTypeNamedParamNode("a", isUntypedTypeLevelReferenceNode("Int")) ) )) ); @@ -93,12 +93,12 @@ public class ParserFunctionTypeTests { assertThat( node, isUntypedFunctionTypeNode() - .withParams(isUntypedParamTypesNode( + .withParams(isUntypedFunctionTypeParamsNode( isSequence(), isSequence( - isUntypedParamNode("a", isUntypedTypeLevelReferenceNode("Int")), - isUntypedParamNode("b", isUntypedTypeLevelReferenceNode("String")), - isUntypedParamNode("c", isUntypedTypeLevelReferenceNode("Bool")) + isUntypedFunctionTypeNamedParamNode("a", isUntypedTypeLevelReferenceNode("Int")), + isUntypedFunctionTypeNamedParamNode("b", isUntypedTypeLevelReferenceNode("String")), + isUntypedFunctionTypeNamedParamNode("c", isUntypedTypeLevelReferenceNode("Bool")) ) )) ); @@ -113,12 +113,12 @@ public class ParserFunctionTypeTests { assertThat( node, isUntypedFunctionTypeNode() - .withParams(isUntypedParamTypesNode( + .withParams(isUntypedFunctionTypeParamsNode( isSequence( isUntypedTypeLevelReferenceNode("Int") ), isSequence( - isUntypedParamNode("b", isUntypedTypeLevelReferenceNode("String")) + isUntypedFunctionTypeNamedParamNode("b", isUntypedTypeLevelReferenceNode("String")) ) )) ); @@ -143,7 +143,7 @@ public class ParserFunctionTypeTests { assertThat( node, isUntypedFunctionTypeNode() - .withParams(isUntypedParamTypesNode( + .withParams(isUntypedFunctionTypeParamsNode( isSequence( isUntypedTypeLevelReferenceNode("Int") ), -- cgit v1.2.3