diff --git a/soundchanger/change.py b/soundchanger/change.py index 9f1942c..7635f0f 100644 --- a/soundchanger/change.py +++ b/soundchanger/change.py @@ -2,7 +2,10 @@ import re def apply(changes, strings, categories={}, ignore_errors=True, apply=True, zero_characters=['∅']): - """Apply a sound change to a given string""" + """ + Applies a sound change or a list of sound changes to a string or + a list of given strings. + """ if not apply: return strings @@ -13,13 +16,15 @@ def apply(changes, strings, categories={}, ignore_errors=True, apply=True, zero_ return_str = isinstance(strings, str) if isinstance(strings, str): strings = [strings] + else: + strings = strings.copy() for change in changes: - v = validate_change(change, ignore_errors=ignore_errors) - if v == False: + + if validate_change(change, ignore_errors=ignore_errors) == False: continue - change = convert_change_to_regex(change, categories=categories, zero_characters=zero_characters) + change = convert_change_to_regex(change, categories=categories, zero_characters=zero_characters) original, change_to, before, after = split_change(change) pattern = f"({before})({original})({after})" @@ -74,4 +79,4 @@ def split_change(change): original, change_to = change.split('>') before, after = environment.split('_') - return (original, change_to, before, after) \ No newline at end of file + return (original, change_to, before, after) diff --git a/tests/test_change.py b/tests/test_change.py index b952311..0ad88f3 100644 --- a/tests/test_change.py +++ b/tests/test_change.py @@ -92,3 +92,8 @@ def test_multiple_changes_and_strings(): def test_applying_invalid_change(): assert apply('', 'pana') == 'pana' assert apply(['p>f', '>', 'f>h'], 'pana') == 'hana' + +def test_original_list_remains_unchanged(): + strings = ['abc', 'bcd', 'cde'] + new_strings = apply('c>f', strings) + assert strings != new_strings