aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/shedlang/compiler/parser
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-10-29 20:42:56 +0000
committerMichael Williamson <mike@zwobble.org>2023-10-29 20:42:56 +0000
commit927ae58be68fcf2a541c1af2a7b27d845e97dea6 (patch)
tree8497dc99343923037f331a129752321ef8a191c0 /src/test/java/org/shedlang/compiler/parser
parente7e76ee0917f7f77966af69a7bca68ba37e4252e (diff)
Parse params without types
Diffstat (limited to 'src/test/java/org/shedlang/compiler/parser')
-rw-r--r--src/test/java/org/shedlang/compiler/parser/ParserFunctionSignatureTests.java39
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()
))