aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-06-06 20:05:58 +0100
committerMichael Williamson <mike@zwobble.org>2023-06-06 20:05:58 +0100
commit3cb64a2536dabcb89f449e81fa5453e528ecd446 (patch)
tree32c0f6632d7931e38af17d97a687340b52393844 /src/test/java
parent9d51478ffc90b4b7d059c38cae25beafe63eb40b (diff)
Only allow positional args before named args
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/parser/ParserCallTests.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/parser/ParserCallTests.java b/src/test/java/org/shedlang/compiler/parser/ParserCallTests.java
index 1020b430..d75c6643 100644
--- a/src/test/java/org/shedlang/compiler/parser/ParserCallTests.java
+++ b/src/test/java/org/shedlang/compiler/parser/ParserCallTests.java
@@ -2,6 +2,7 @@ package org.shedlang.compiler.parser;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.shedlang.compiler.ast.UntypedNodeMatchers.*;
import static org.shedlang.compiler.parser.ParserTesting.parseString;
import static org.zwobble.precisely.AssertThat.assertThat;
@@ -121,6 +122,37 @@ public class ParserCallTests {
}
@Test
+ public void canParseNamedArgumentAfterPositionalArgument() {
+ var source = "f(a, .named = b)";
+
+ var node = parseString(source, Parser::parseTopLevelExpression);
+
+ assertThat(
+ node,
+ isUntypedCallNode()
+ .withArgs(
+ isUntypedArgsNode()
+ .withPositional(isSequence(
+ isUntypedReferenceNode("a")
+ ))
+ .withNamed(isSequence(
+ isUntypedNamedArgNode("named", isUntypedReferenceNode("b"))
+ ))
+ )
+ );
+ }
+
+ @Test
+ public void cannotParsePositionalArgumentAfterNamedArgument() {
+ var source = "f(.y = false, true)";
+
+ assertThrows(
+ PositionalArgAfterNamedArgError.class,
+ () -> parseString(source, Parser::parseTopLevelExpression)
+ );
+ }
+
+ @Test
public void argumentListCanHaveTrailingComma() {
var source = "f(a,)";