map tests
This commit is contained in:
parent
a01c658fed
commit
fe3d0beaed
4 changed files with 29 additions and 3 deletions
|
|
@ -13,6 +13,7 @@ from ytdl_sub.script.types.resolvable import String
|
|||
from ytdl_sub.script.types.syntax_tree import SyntaxTree
|
||||
from ytdl_sub.script.types.variable import FunctionArgument
|
||||
from ytdl_sub.script.types.variable import Variable
|
||||
from ytdl_sub.script.utils.exceptions import InvalidSyntaxException
|
||||
from ytdl_sub.utils.exceptions import StringFormattingException
|
||||
from ytdl_sub.validators.string_formatter_validators import is_valid_source_variable_name
|
||||
|
||||
|
|
@ -229,7 +230,7 @@ class _Parser:
|
|||
while ch := self._read(increment_pos=False):
|
||||
if ch == "}":
|
||||
if key is not None:
|
||||
raise StringFormattingException("Key with no value")
|
||||
raise InvalidSyntaxException("Map has a key with no value")
|
||||
|
||||
self._pos += 1
|
||||
return UnresolvedMap(value=output)
|
||||
|
|
@ -237,7 +238,7 @@ class _Parser:
|
|||
if in_comma:
|
||||
raise StringFormattingException("Comma followed by comma")
|
||||
if key is not None:
|
||||
raise StringFormattingException("key followed by comma")
|
||||
raise InvalidSyntaxException("Map has a key with no value")
|
||||
if output is None:
|
||||
raise StringFormattingException("Empty dict with comma")
|
||||
in_comma = True
|
||||
|
|
@ -252,7 +253,7 @@ class _Parser:
|
|||
self._pos += 1
|
||||
value_args = self._parse_args(breaking_chars=",}")
|
||||
if len(value_args) != 1:
|
||||
raise StringFormattingException("Lazy parsing, no value")
|
||||
raise InvalidSyntaxException("Map has a key with no value")
|
||||
|
||||
output[key] = value_args[0]
|
||||
key = None
|
||||
|
|
|
|||
0
src/ytdl_sub/script/utils/__init__.py
Normal file
0
src/ytdl_sub/script/utils/__init__.py
Normal file
5
src/ytdl_sub/script/utils/exceptions.py
Normal file
5
src/ytdl_sub/script/utils/exceptions.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from ytdl_sub.utils.exceptions import ValidationException
|
||||
|
||||
|
||||
class InvalidSyntaxException(ValidationException):
|
||||
"""Syntax is incorrect"""
|
||||
|
|
@ -1,7 +1,12 @@
|
|||
import re
|
||||
|
||||
import pytest
|
||||
|
||||
from ytdl_sub.script.script import Script
|
||||
from ytdl_sub.script.types.map import ResolvedMap
|
||||
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 TestMap:
|
||||
|
|
@ -54,3 +59,18 @@ class TestMap:
|
|||
|
||||
def test_empty_map(self):
|
||||
assert Script({"map": "{{}}"}).resolve() == {"map": ResolvedMap({})}
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value",
|
||||
[
|
||||
"{{'key': }}",
|
||||
"{{'key':}}",
|
||||
"{{'key': 'value', 'key2':}}",
|
||||
"{{'key': 'value', 'key2': }}",
|
||||
"{{ 'key': 'value', 'key2':\n}}",
|
||||
"{{ 'key': ,\n}}",
|
||||
],
|
||||
)
|
||||
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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue