diff options
Diffstat (limited to 'src/test/java/org/shedlang/compiler/parser')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/parser/ParserFunctionSignatureTests.java | 39 |
1 files changed, 28 insertions, 11 deletions
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() )) |
