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( change='p>h/#_{u,i}Na#', string=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_with_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_multiple_changes(): string = 'pana' for change in ['p>f', 'n>m/fa_']: string = apply(change, string) assert string == 'fama' def test_change_from_category(): assert apply('V>o', 'tatiru', categories={ 'V': 'aiu' }) == 'totoro'