diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-10-29 20:42:56 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-10-29 20:42:56 +0000 |
| commit | 927ae58be68fcf2a541c1af2a7b27d845e97dea6 (patch) | |
| tree | 8497dc99343923037f331a129752321ef8a191c0 /src/test/java | |
| parent | e7e76ee0917f7f77966af69a7bca68ba37e4252e (diff) | |
Parse params without types
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java | 3 | ||||
| -rw-r--r-- | src/test/java/org/shedlang/compiler/parser/ParserFunctionSignatureTests.java | 39 |
2 files changed, 30 insertions, 12 deletions
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 db788968..4810f7e7 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java @@ -5,6 +5,7 @@ import org.shedlang.compiler.types.Visibility; import org.zwobble.precisely.Matcher; import java.math.BigInteger; +import java.util.Optional; import static org.zwobble.precisely.Matchers.*; @@ -202,7 +203,7 @@ public class UntypedNodeMatchers { public static Matcher<UntypedParamNode> isUntypedParamNode( String name, - Matcher<UntypedTypeLevelExpressionNode> type + Matcher<Optional<? extends UntypedTypeLevelExpressionNode>> type ) { return allOf( has("name", x -> x.name(), equalTo(name)), diff --git a/src/test/java/org/shedlang/compiler/parser/ParserFunctionSignatureTests.java b/src/test/java/org/shedlang/compiler/parser/ParserFunctionSignatureTests.java index 797d112d..f26efa64 100644 --- a/src/test/java/org/shedlang/compiler/parser/ParserFunctionSignatureTests.java +++ b/src/test/java/org/shedlang/compiler/parser/ParserFunctionSignatureTests.java @@ -34,7 +34,7 @@ public class ParserFunctionSignatureTests { node, isUntypedFunctionSignatureNode().withParams(isUntypedParamsNode( isSequence( - isUntypedParamNode("a", isUntypedTypeLevelReferenceNode("Int")) + isUntypedParamNode("a", isOptionalOf(isUntypedTypeLevelReferenceNode("Int"))) ), isSequence() )) @@ -51,9 +51,9 @@ public class ParserFunctionSignatureTests { node, isUntypedFunctionSignatureNode().withParams(isUntypedParamsNode( isSequence( - isUntypedParamNode("a", isUntypedTypeLevelReferenceNode("Int")), - isUntypedParamNode("b", isUntypedTypeLevelReferenceNode("String")), - isUntypedParamNode("c", isUntypedTypeLevelReferenceNode("Bool")) + isUntypedParamNode("a", isOptionalOf(isUntypedTypeLevelReferenceNode("Int"))), + isUntypedParamNode("b", isOptionalOf(isUntypedTypeLevelReferenceNode("String"))), + isUntypedParamNode("c", isOptionalOf(isUntypedTypeLevelReferenceNode("Bool"))) ), isSequence() )) @@ -71,7 +71,7 @@ public class ParserFunctionSignatureTests { isUntypedFunctionSignatureNode().withParams(isUntypedParamsNode( isSequence(), isSequence( - isUntypedParamNode("a", isUntypedTypeLevelReferenceNode("Int")) + isUntypedParamNode("a", isOptionalOf(isUntypedTypeLevelReferenceNode("Int"))) ) )) ); @@ -88,9 +88,9 @@ public class ParserFunctionSignatureTests { isUntypedFunctionSignatureNode().withParams(isUntypedParamsNode( isSequence(), isSequence( - isUntypedParamNode("a", isUntypedTypeLevelReferenceNode("Int")), - isUntypedParamNode("b", isUntypedTypeLevelReferenceNode("String")), - isUntypedParamNode("c", isUntypedTypeLevelReferenceNode("Bool")) + isUntypedParamNode("a", isOptionalOf(isUntypedTypeLevelReferenceNode("Int"))), + isUntypedParamNode("b", isOptionalOf(isUntypedTypeLevelReferenceNode("String"))), + isUntypedParamNode("c", isOptionalOf(isUntypedTypeLevelReferenceNode("Bool"))) ) )) ); @@ -106,10 +106,10 @@ public class ParserFunctionSignatureTests { node, isUntypedFunctionSignatureNode().withParams(isUntypedParamsNode( isSequence( - isUntypedParamNode("a", isUntypedTypeLevelReferenceNode("Int")) + isUntypedParamNode("a", isOptionalOf(isUntypedTypeLevelReferenceNode("Int"))) ), isSequence( - isUntypedParamNode("b", isUntypedTypeLevelReferenceNode("String")) + isUntypedParamNode("b", isOptionalOf(isUntypedTypeLevelReferenceNode("String"))) ) )) ); @@ -126,6 +126,23 @@ public class ParserFunctionSignatureTests { } @Test + public void canParseParamWithoutType() { + var source = "(a) -> Unit"; + + var node = parseString(source, Parser::parseFunctionSignature); + + assertThat( + node, + isUntypedFunctionSignatureNode().withParams(isUntypedParamsNode( + isSequence( + isUntypedParamNode("a", isOptionalEmpty()) + ), + isSequence() + )) + ); + } + + @Test public void paramsCanHaveTrailingComma() { var source = "(a: Int, ) -> Unit"; @@ -135,7 +152,7 @@ public class ParserFunctionSignatureTests { node, isUntypedFunctionSignatureNode().withParams(isUntypedParamsNode( isSequence( - isUntypedParamNode("a", isUntypedTypeLevelReferenceNode("Int")) + isUntypedParamNode("a", isOptionalOf(isUntypedTypeLevelReferenceNode("Int"))) ), isSequence() )) |
