soundchanger/tests/test_apply.py
2023-02-21 15:25:53 +09:00

100 lines
3.1 KiB
Python

from soundchanger.change import apply
def test_without_environment():
assert apply('p>h', 'pana') == 'hana'
def test_with_environment():
assert apply('p>f/#_u', 'pune') == 'fune'
def test_with_partial_environment():
assert apply('p>h/#_', 'pi') == 'hi'
assert apply('p>h/_i', 'pi') == 'hi'
def test_change_to_nothing():
assert apply('u>', 'fun') == 'fn'
def test_change_to_nothing_with_environment():
assert apply('u>/_n#', 'fun') == 'fn'
def test_change_to_zero_character_with_environment():
assert apply('w>∅', 'kawa') == 'kaa'
def test_custom_zero_character():
assert apply('w>-', 'kawa', zero_characters=['-']) == 'kaa'
def test_whitespace_in_change():
assert apply(' a > b / c _ d ', 'cad') == 'cbd'
def test_multiple_underscores_in_environment():
assert apply('a>b/c___d ', 'cad') == 'cbd'
def test_categories_as_string():
assert apply('V>o', 'ha', categories={'V': 'aiu'}) == 'ho'
assert apply('V>o', 'he', categories={'V': 'aiu'}) == 'he'
def test_categories_as_list():
assert apply('V>o', 'ha', categories={'V': ['a', 'i', 'u']}) == 'ho'
assert apply('V>o', 'he', categories={'V': ['a', 'i', 'u']}) == 'he'
def test_complex_environment():
inputs = ['pana', 'pina', 'puna', 'pama', 'pima', 'puma']
outputs = ['pana', 'hina', 'huna', 'pama', 'hima', 'huma']
for string, output in zip(inputs, outputs):
assert apply('p>h/#_{u,i}Na#', string,
categories={'N': 'nm'}
) == output
def test_complex_group_and_categories():
assert apply('e>i/{#,p,t,k}V{m,n,h}_#', 'pane', categories={
'V': 'aiu',
'P': 'ptk',
'N': 'mn',
}) == 'pani'
def test_complex_group_and_categories_and_digraphs():
assert apply('u>o/#V{ts,pf,t}_k{V,e,o}#', 'atsuka', categories={
'V': ['a', 'i', 'u']
}) == 'atsoka'
assert apply('u>o/#V{ts,pf,t}_k{V,e,o}#', 'atuka', categories={
'V': ['a', 'i', 'u']
}) == 'atoka'
assert apply('u>o/#V{ts,pf,t}_k{V,e,o}#', 'matsuka', categories={
'V': ['a', 'i', 'u']
}) == 'matsuka'
def test_change_from_category():
assert apply('V>o', 'tatiru', categories={
'V': 'aiu'
}) == 'totoro'
def test_list_and_str_inputs():
assert apply('a>b', 'cad') == 'cbd'
assert apply(['a>b'], 'cad') == 'cbd'
assert apply('a>b', ['cad']) == ['cbd']
assert apply(['a>b'], ['cad']) == ['cbd']
def test_multiple_changes():
string = 'pana'
for change in ['p>f', 'n>m/fa_']:
string = apply(change, string)
assert string == 'fama'
assert apply(['p>f', 'n>m/fa_'], string) == 'fama'
def test_multiple_strings():
assert apply('p>f', ['pana', 'pune']) == [
'fana', 'fune'
]
def test_multiple_changes_and_strings():
assert apply(['p>f', 'f>h/#_a'], ['pana', 'pune']) == ['hana', 'fune']
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