def _get_text_from_candidates(candidates): if len(candidates) == 0: return "" elif len(candidates) == 1: return jamo_to_hcj(candidates[0]) else: return j2h(**dict(zip(["lead", "vowel", "tail"], candidates)))
def test_jamo_to_hcj(self): """jamo_to_hcj tests Arguments may be iterables or single characters. jamo_to_hcj should convert every U+11xx jamo character into U+31xx HCJ in a given input. Anything else is unchanged. """ test_chars = itertools.chain(_JAMO_LEADS_MODERN, _JAMO_VOWELS_MODERN, _JAMO_TAILS_MODERN) target_chars = itertools.chain(_HCJ_LEADS_MODERN, _HCJ_VOWELS_MODERN, _HCJ_TAILS_MODERN) # TODO: Complete archaic jamo coverage test_archaic = ["ᄀᄁᄂᄃᇹᇫ"] target_archaic = ["ㄱㄲㄴㄷㆆㅿ"] test_strings_idempotent = ["", "aAzZ ,.:;~`―—–/!@#$%^&*()[]{}", "汉语 / 漢語; Hànyǔ or 中文; Zhōngwén", "ㄱㆎ"] target_strings_idempotent = test_strings_idempotent # TODO: Add more tests for unmapped jamo characters. test_strings_unmapped = ["ᅶᅷᅸᅹᅺᅻᅼᅽᅾᅿᆆ", ""] target_strings_unmapped = test_strings_unmapped all_tests = itertools.chain(zip(test_chars, target_chars), zip(test_archaic, target_archaic), zip(test_strings_idempotent, target_strings_idempotent), zip(test_strings_unmapped, target_strings_unmapped)) for test, target in all_tests: trial = jamo.jamo_to_hcj(test) assert trial.__name__ == "<genexpr>",\ "jamo_to_hcj didn't return an instance of a generator." trial, target = ''.join(trial), ''.join(target) assert trial == target,\ ("Matched {test} to {trial}, but " "expected {target}.").format(test=''.join(test), trial=trial, target=target)
def test_jamo_to_hcj(self): """jamo_to_hcj tests Arguments may be iterables or single characters. jamo_to_hcj should convert every U+11xx jamo character into U+31xx HCJ in a given input. Anything else is unchanged. """ test_chars = itertools.chain(_JAMO_LEADS_MODERN, _JAMO_VOWELS_MODERN, _JAMO_TAILS_MODERN) target_chars = itertools.chain(_HCJ_LEADS_MODERN, _HCJ_VOWELS_MODERN, _HCJ_TAILS_MODERN) # TODO: Complete archaic jamo coverage test_archaic = ["ᄀᄁᄂᄃᇹᇫ"] target_archaic = ["ㄱㄲㄴㄷㆆㅿ"] test_strings_idempotent = [ "", "aAzZ ,.:;~`―—–/!@#$%^&*()[]{}", "汉语 / 漢語; Hànyǔ or 中文; Zhōngwén", "ㄱㆎ" ] target_strings_idempotent = test_strings_idempotent # TODO: Add more tests for unmapped jamo characters. test_strings_unmapped = ["ᅶᅷᅸᅹᅺᅻᅼᅽᅾᅿᆆ", ""] target_strings_unmapped = test_strings_unmapped all_tests = itertools.chain( zip(test_chars, target_chars), zip(test_archaic, target_archaic), zip(test_strings_idempotent, target_strings_idempotent), zip(test_strings_unmapped, target_strings_unmapped)) for test, target in all_tests: trial = jamo.jamo_to_hcj(test) assert trial.__name__ == "<genexpr>",\ "jamo_to_hcj didn't return an instance of a generator." trial, target = ''.join(trial), ''.join(target) assert trial == target,\ ("Matched {test} to {trial}, but " "expected {target}.").format(test=''.join(test), trial=trial, target=target)