diff --git a/tests/unit/script/types/test_array.py b/tests/unit/script/types/test_array.py index b3ea68c7..f7f20095 100644 --- a/tests/unit/script/types/test_array.py +++ b/tests/unit/script/types/test_array.py @@ -7,6 +7,7 @@ from ytdl_sub.script.parser import UNEXPECTED_COMMA_ARGUMENT from ytdl_sub.script.parser import ArgumentParser from ytdl_sub.script.script import Script from ytdl_sub.script.types.array import ResolvedArray +from ytdl_sub.script.types.resolvable import Boolean from ytdl_sub.script.types.resolvable import Float from ytdl_sub.script.types.resolvable import String from ytdl_sub.script.utils.exceptions import InvalidSyntaxException @@ -23,6 +24,18 @@ class TestArray: "array": String('str: ["a", 3.14]') } + @pytest.mark.parametrize( + "array, expected_bool", + [ + ("{%bool([])}", False), + ("{%bool([False])}", True), + ], + ) + def test_return_as_bool(self, array: str, expected_bool: bool): + assert Script({"array_as_bool": array}).resolve() == { + "array_as_bool": Boolean(expected_bool) + } + def test_nested_array(self): assert Script( {"array": "{['level1', ['level2', ['level3', 'level3'], 'level2'], 'level1']}"} diff --git a/tests/unit/script/types/test_float.py b/tests/unit/script/types/test_float.py index acbd0016..8d2c97bd 100644 --- a/tests/unit/script/types/test_float.py +++ b/tests/unit/script/types/test_float.py @@ -10,6 +10,7 @@ from ytdl_sub.script.parser import UNEXPECTED_COMMA_ARGUMENT from ytdl_sub.script.parser import ArgumentParser from ytdl_sub.script.script import Script from ytdl_sub.script.types.array import ResolvedArray +from ytdl_sub.script.types.resolvable import Boolean from ytdl_sub.script.types.resolvable import Float from ytdl_sub.script.types.resolvable import Integer from ytdl_sub.script.types.resolvable import String @@ -49,6 +50,16 @@ class TestFloat: "as_string": String(str(expected_float)), } + @pytest.mark.parametrize( + "float_, expected_bool", + [ + ("{%bool(0.0)}", False), + ("{%bool(0.1)}", True), + ], + ) + def test_return_as_bool(self, float_: str, expected_bool: bool): + assert Script({"as_bool": float_}).resolve() == {"as_bool": Boolean(expected_bool)} + @pytest.mark.parametrize( "float_", [ diff --git a/tests/unit/script/types/test_integer.py b/tests/unit/script/types/test_integer.py index a7237ede..02ed5055 100644 --- a/tests/unit/script/types/test_integer.py +++ b/tests/unit/script/types/test_integer.py @@ -10,6 +10,7 @@ from ytdl_sub.script.parser import UNEXPECTED_COMMA_ARGUMENT from ytdl_sub.script.parser import ArgumentParser from ytdl_sub.script.script import Script from ytdl_sub.script.types.array import ResolvedArray +from ytdl_sub.script.types.resolvable import Boolean from ytdl_sub.script.types.resolvable import Float from ytdl_sub.script.types.resolvable import Integer from ytdl_sub.script.types.resolvable import String @@ -49,6 +50,16 @@ class TestInteger: "as_string": String(str(expected_integer)), } + @pytest.mark.parametrize( + "integer, expected_bool", + [ + ("{%bool(0)}", False), + ("{%bool(1)}", True), + ], + ) + def test_return_as_bool(self, integer: str, expected_bool: bool): + assert Script({"as_bool": integer}).resolve() == {"as_bool": Boolean(expected_bool)} + @pytest.mark.parametrize( "integer", [ diff --git a/tests/unit/script/types/test_map.py b/tests/unit/script/types/test_map.py index 89285f56..38f8044e 100644 --- a/tests/unit/script/types/test_map.py +++ b/tests/unit/script/types/test_map.py @@ -11,6 +11,7 @@ from ytdl_sub.script.parser import UNEXPECTED_COMMA_ARGUMENT from ytdl_sub.script.parser import ArgumentParser from ytdl_sub.script.script import Script from ytdl_sub.script.types.map import ResolvedMap +from ytdl_sub.script.types.resolvable import Boolean from ytdl_sub.script.types.resolvable import Float from ytdl_sub.script.types.resolvable import String from ytdl_sub.script.utils.exceptions import InvalidSyntaxException @@ -27,6 +28,16 @@ class TestMap: "map": String('json: {"a": 3.14}') } + @pytest.mark.parametrize( + "map_, expected_bool", + [ + ("{%bool({})}", False), + ("{%bool({'key': 'value'})}", True), + ], + ) + def test_return_as_bool(self, map_: str, expected_bool: bool): + assert Script({"as_bool": map_}).resolve() == {"as_bool": Boolean(expected_bool)} + def test_nested_map(self): map_str = """{ { diff --git a/tests/unit/script/types/test_string.py b/tests/unit/script/types/test_string.py index b4413038..d0aa4df4 100644 --- a/tests/unit/script/types/test_string.py +++ b/tests/unit/script/types/test_string.py @@ -12,6 +12,7 @@ from ytdl_sub.script.parser import UNEXPECTED_COMMA_ARGUMENT from ytdl_sub.script.parser import ArgumentParser from ytdl_sub.script.script import Script from ytdl_sub.script.types.array import ResolvedArray +from ytdl_sub.script.types.resolvable import Boolean from ytdl_sub.script.types.resolvable import Float from ytdl_sub.script.types.resolvable import Integer from ytdl_sub.script.types.resolvable import String @@ -37,6 +38,8 @@ class TestString: @pytest.mark.parametrize( "string, expected_string", [ + ("{%string('')}", ""), + ('{%string("")}', ""), ("{%string('323')}", "323"), ('{%string( "4253" )}', "4253"), ('{%string("hi")}', "hi"), @@ -55,6 +58,16 @@ class TestString: def test_string(self, string: str, expected_string: str): assert Script({"string": string}).resolve() == {"string": String(expected_string)} + @pytest.mark.parametrize( + "string, expected_bool", + [ + ("{%bool('')}", False), + ("{%bool('false')}", True), + ], + ) + def test_return_as_bool(self, string: str, expected_bool: bool): + assert Script({"as_bool": string}).resolve() == {"as_bool": Boolean(expected_bool)} + @pytest.mark.parametrize( "string", [