more array tests wip
This commit is contained in:
parent
469d03777e
commit
5ad6973a18
3 changed files with 39 additions and 9 deletions
|
|
@ -29,7 +29,7 @@ UNREACHABLE = UnreachableSyntaxException(
|
|||
"https://github.com/jmbannon/ytdl-sub/issues"
|
||||
)
|
||||
|
||||
UNEXPECTED_ARGUMENT = InvalidSyntaxException("Unexpected comma when parsing arguments")
|
||||
UNEXPECTED_COMMA_ARGUMENT = InvalidSyntaxException("Unexpected comma when parsing arguments")
|
||||
MAP_KEY_WITH_NO_VALUE = InvalidSyntaxException("Map has a key with no value")
|
||||
MAP_KEY_MULTIPLE_VALUES = InvalidSyntaxException(
|
||||
"Map key has multiple values when there should only be one"
|
||||
|
|
@ -207,7 +207,7 @@ class _Parser:
|
|||
comma_count += 1
|
||||
if argument_index != comma_count:
|
||||
self._set_highlight_position()
|
||||
raise UNEXPECTED_ARGUMENT
|
||||
raise UNEXPECTED_COMMA_ARGUMENT
|
||||
|
||||
self._pos += 1
|
||||
else:
|
||||
|
|
@ -247,7 +247,7 @@ class _Parser:
|
|||
else:
|
||||
function_args = self._parse_args(breaking_chars="]")
|
||||
|
||||
raise StringFormattingException("Invalid function")
|
||||
raise UNREACHABLE
|
||||
|
||||
def _parse_map(self) -> UnresolvedMap:
|
||||
"""
|
||||
|
|
@ -267,11 +267,11 @@ class _Parser:
|
|||
return UnresolvedMap(value=output)
|
||||
elif ch == ",":
|
||||
if in_comma:
|
||||
raise UNEXPECTED_ARGUMENT
|
||||
raise UNEXPECTED_COMMA_ARGUMENT
|
||||
if key is not None:
|
||||
raise MAP_KEY_WITH_NO_VALUE
|
||||
if not output:
|
||||
raise UNEXPECTED_ARGUMENT
|
||||
raise UNEXPECTED_COMMA_ARGUMENT
|
||||
in_comma = True
|
||||
self._pos += 1
|
||||
elif key is None:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,13 @@
|
|||
import re
|
||||
|
||||
import pytest
|
||||
|
||||
from ytdl_sub.script.parser import UNEXPECTED_COMMA_ARGUMENT
|
||||
from ytdl_sub.script.script import Script
|
||||
from ytdl_sub.script.types.array import ResolvedArray
|
||||
from ytdl_sub.script.types.resolvable import Float
|
||||
from ytdl_sub.script.types.resolvable import String
|
||||
from ytdl_sub.script.utils.exceptions import InvalidSyntaxException
|
||||
|
||||
|
||||
class TestArray:
|
||||
|
|
@ -34,8 +40,32 @@ class TestArray:
|
|||
)
|
||||
}
|
||||
|
||||
def test_empty_array(self):
|
||||
assert Script({"array": "{[]}"}).resolve() == {"array": ResolvedArray([])}
|
||||
@pytest.mark.parametrize(
|
||||
"array",
|
||||
[
|
||||
"{[]}",
|
||||
"{ [] }",
|
||||
"{ [ ] }",
|
||||
"{[\n]}",
|
||||
],
|
||||
)
|
||||
def test_empty(self, array: str):
|
||||
assert Script({"array": array}).resolve() == {"array": ResolvedArray([])}
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"array",
|
||||
[
|
||||
"{[,]}",
|
||||
"{[ ,]}",
|
||||
"{ [ , ]}",
|
||||
"{ ['test',] }",
|
||||
"{ [ 'test', ] }",
|
||||
"{[\n,\n]}",
|
||||
],
|
||||
)
|
||||
def test_unexpected_comma(self, array: str):
|
||||
with pytest.raises(InvalidSyntaxException, match=re.escape(str(UNEXPECTED_COMMA_ARGUMENT))):
|
||||
Script({"array": array}).resolve()
|
||||
|
||||
def test_custom_function(self):
|
||||
assert Script(
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from ytdl_sub.script.parser import MAP_KEY_MULTIPLE_VALUES
|
|||
from ytdl_sub.script.parser import MAP_KEY_NOT_HASHABLE
|
||||
from ytdl_sub.script.parser import MAP_KEY_WITH_NO_VALUE
|
||||
from ytdl_sub.script.parser import MAP_MISSING_KEY
|
||||
from ytdl_sub.script.parser import UNEXPECTED_ARGUMENT
|
||||
from ytdl_sub.script.parser import UNEXPECTED_COMMA_ARGUMENT
|
||||
from ytdl_sub.script.script import Script
|
||||
from ytdl_sub.script.types.map import ResolvedMap
|
||||
from ytdl_sub.script.types.resolvable import Float
|
||||
|
|
@ -99,7 +99,7 @@ class TestMap:
|
|||
],
|
||||
)
|
||||
def test_map_unexpected_comma(self, value: str):
|
||||
with pytest.raises(InvalidSyntaxException, match=re.escape(str(UNEXPECTED_ARGUMENT))):
|
||||
with pytest.raises(InvalidSyntaxException, match=re.escape(str(UNEXPECTED_COMMA_ARGUMENT))):
|
||||
Script({"map": value}).resolve()
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
|
|||
Loading…
Reference in a new issue