unexpected comma

This commit is contained in:
Jesse Bannon 2023-11-10 09:24:53 -08:00
parent ed8ab12a3b
commit f9c30f9f7f
2 changed files with 16 additions and 2 deletions

View file

@ -188,7 +188,8 @@ class _Parser:
elif ch == ",":
comma_count += 1
if argument_index != comma_count:
raise StringFormattingException("Comma argument shenanigans")
self._set_highlight_position()
raise InvalidSyntaxException("Unexpected comma when parsing arguments")
self._pos += 1
else:
@ -252,7 +253,7 @@ class _Parser:
if key is not None:
raise InvalidSyntaxException("Map has a key with no value")
if output is None:
raise StringFormattingException("Empty dict with comma")
raise InvalidSyntaxException("Map has an extra comma")
in_comma = True
self._pos += 1
elif key is None:

View file

@ -74,3 +74,16 @@ class TestMap:
def test_key_has_no_value(self, value: str):
with pytest.raises(InvalidSyntaxException, match=re.escape("Map has a key with no value")):
Script({"map": value}).resolve()
@pytest.mark.parametrize(
"value",
[
"{{ , }}",
"{{'key': 'value', ,}}",
],
)
def test_map_unexpected_comma(self, value: str):
with pytest.raises(
InvalidSyntaxException, match=re.escape("Unexpected comma when parsing arguments")
):
Script({"map": value}).resolve()