diff --git a/src/ytdl_sub/script/functions/string_functions.py b/src/ytdl_sub/script/functions/string_functions.py index 574b6113..d54f0744 100644 --- a/src/ytdl_sub/script/functions/string_functions.py +++ b/src/ytdl_sub/script/functions/string_functions.py @@ -55,8 +55,8 @@ class StringFunctions: return String(string.value.replace(old.value, new.value)) @staticmethod - def concat(*args: String) -> String: + def concat(*values: String) -> String: """ Concatenate multiple Strings into a single String. """ - return String("".join(*args)) + return String("".join(list([val.value for val in values]))) diff --git a/tests/unit/script/functions/test_string_functions.py b/tests/unit/script/functions/test_string_functions.py new file mode 100644 index 00000000..7352debe --- /dev/null +++ b/tests/unit/script/functions/test_string_functions.py @@ -0,0 +1,78 @@ +import pytest +from unit.script.conftest import single_variable_output + +from ytdl_sub.script.script import Script + + +class TestNumericFunctions: + @pytest.mark.parametrize( + "values, expected_output", + [ + ("'lower'", "LOWER"), + ("'UPPER'", "UPPER"), + ], + ) + def test_upper(self, values: str, expected_output: str): + output = single_variable_output(f"{{%upper({values})}}") + assert output == expected_output + + @pytest.mark.parametrize( + "values, expected_output", + [ + ("'lower'", "lower"), + ("'UPPER'", "upper"), + ], + ) + def test_lower(self, values: str, expected_output: str): + output = single_variable_output(f"{{%lower({values})}}") + assert output == expected_output + + @pytest.mark.parametrize( + "values, expected_output", + [ + ("'lower First word'", "Lower first word"), + ("'UPPER First word'", "Upper first word"), + ], + ) + def test_capitalize(self, values: str, expected_output: str): + output = single_variable_output(f"{{%capitalize({values})}}") + assert output == expected_output + + @pytest.mark.parametrize( + "values, expected_output", + [ + ("'lower First word'", "Lower First Word"), + ("'UPPER First word'", "Upper First Word"), + ], + ) + def test_titlecase(self, values: str, expected_output: str): + output = single_variable_output(f"{{%titlecase({values})}}") + assert output == expected_output + + @pytest.mark.parametrize( + "values, expected_output", + [ + ( + "'lower First word second word', 'word', 'string'", + "lower First string second string", + ), + ( + "'lower First word second word', 'word', 'string', 1", + "lower First string second word", + ), + ], + ) + def test_replace(self, values: str, expected_output: str): + output = single_variable_output(f"{{%replace({values})}}") + assert output == expected_output + + @pytest.mark.parametrize( + "values, expected_output", + [ + ("'lower First word'", "lower First word"), + ("'lower First word', ' second', ' string'", "lower First word second string"), + ], + ) + def test_concat(self, values: str, expected_output: str): + output = single_variable_output(f"{{%concat({values})}}") + assert output == expected_output