unexpected comma
This commit is contained in:
parent
ed8ab12a3b
commit
f9c30f9f7f
2 changed files with 16 additions and 2 deletions
|
|
@ -188,7 +188,8 @@ class _Parser:
|
||||||
elif ch == ",":
|
elif ch == ",":
|
||||||
comma_count += 1
|
comma_count += 1
|
||||||
if argument_index != comma_count:
|
if argument_index != comma_count:
|
||||||
raise StringFormattingException("Comma argument shenanigans")
|
self._set_highlight_position()
|
||||||
|
raise InvalidSyntaxException("Unexpected comma when parsing arguments")
|
||||||
|
|
||||||
self._pos += 1
|
self._pos += 1
|
||||||
else:
|
else:
|
||||||
|
|
@ -252,7 +253,7 @@ class _Parser:
|
||||||
if key is not None:
|
if key is not None:
|
||||||
raise InvalidSyntaxException("Map has a key with no value")
|
raise InvalidSyntaxException("Map has a key with no value")
|
||||||
if output is None:
|
if output is None:
|
||||||
raise StringFormattingException("Empty dict with comma")
|
raise InvalidSyntaxException("Map has an extra comma")
|
||||||
in_comma = True
|
in_comma = True
|
||||||
self._pos += 1
|
self._pos += 1
|
||||||
elif key is None:
|
elif key is None:
|
||||||
|
|
|
||||||
|
|
@ -74,3 +74,16 @@ class TestMap:
|
||||||
def test_key_has_no_value(self, value: str):
|
def test_key_has_no_value(self, value: str):
|
||||||
with pytest.raises(InvalidSyntaxException, match=re.escape("Map has a key with no value")):
|
with pytest.raises(InvalidSyntaxException, match=re.escape("Map has a key with no value")):
|
||||||
Script({"map": value}).resolve()
|
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()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue