From 6a459ab114a6523e01fc6530a439e3d923e87062 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Thu, 23 Nov 2023 00:45:46 -0800 Subject: [PATCH] better test --- src/ytdl_sub/script/functions/string_functions.py | 9 ++++++++- tests/unit/script/test_script.py | 10 +++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/ytdl_sub/script/functions/string_functions.py b/src/ytdl_sub/script/functions/string_functions.py index 61e42542..574b6113 100644 --- a/src/ytdl_sub/script/functions/string_functions.py +++ b/src/ytdl_sub/script/functions/string_functions.py @@ -30,10 +30,17 @@ class StringFunctions: @staticmethod def capitalize(string: String) -> String: """ - Capitalize all words in the String. + Capitalize the first character in the string. """ return String(string.value.capitalize()) + @staticmethod + def titlecase(string: String) -> String: + """ + Capitalize each word in the string. + """ + return String(string.value.title()) + @staticmethod def replace( string: String, old: String, new: String, count: Optional[Integer] = None diff --git a/tests/unit/script/test_script.py b/tests/unit/script/test_script.py index 80b2126f..0c668fb8 100644 --- a/tests/unit/script/test_script.py +++ b/tests/unit/script/test_script.py @@ -29,6 +29,9 @@ class TestScript: ).resolve(unresolvable={"bb"}) == {"aa": String("a")} def test_partial_update_script(self): + # to be resolved later + entry_map = ResolvedMap({String("title"): String("the title")}) + script = Script( { "entry": "{%throw('entry has not been populated yet')}", @@ -44,13 +47,14 @@ class TestScript: script.add( { + "new_variable_titlecase": "{%titlecase(new_variable_upper)}", "new_variable": "{resolved_override} {title}", "new_variable_upper": "{%upper(new_variable)}", } - ).resolve( - resolved={"entry": ResolvedMap({String("title"): String("the title")})}, update=True - ) + ).resolve(resolved={"entry": entry_map}, update=True) assert script.get("title") == String("the title") assert script.get("new_variable") == String("hi mom the title") assert script.get("new_variable_upper") == String("HI MOM THE TITLE") + assert script.get("new_variable_titlecase") == String("Hi Mom The Title") + assert script.get("entry") == entry_map