From 3cb64a2536dabcb89f449e81fa5453e528ecd446 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 6 Jun 2023 20:05:58 +0100 Subject: Only allow positional args before named args --- .../shedlang/compiler/parser/ParserCallTests.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/test/java') 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; @@ -120,6 +121,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,)"; -- cgit v1.2.3