From 927ae58be68fcf2a541c1af2a7b27d845e97dea6 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 29 Oct 2023 20:42:56 +0000 Subject: Parse params without types --- .../parser/ParserFunctionSignatureTests.java | 39 ++++++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'src/test/java/org/shedlang/compiler/parser') 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"))) ) )) ); @@ -125,6 +125,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() )) -- cgit v1.2.3