diff options
Diffstat (limited to 'test/test.c')
-rw-r--r-- | test/test.c | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/test/test.c b/test/test.c index 788231d..484a0c1 100644 --- a/test/test.c +++ b/test/test.c @@ -5,6 +5,122 @@ #define countof(x) ((sizeof(x)) / (sizeof(x[0]))) +START_TEST(test_hangul_ic_process_romaja) +{ + HangulInputContext* ic; + const ucschar* preedit; + const ucschar* commit; + + // romaja keyboard test + ic = hangul_ic_new("ro"); + + // basic test: han produces 한 + hangul_ic_process(ic, 'h'); + hangul_ic_process(ic, 'a'); + hangul_ic_process(ic, 'n'); + + preedit = hangul_ic_get_preedit_string(ic); + commit = hangul_ic_get_commit_string(ic); + fail_unless(preedit[0] == 0xd55c); // 한 + fail_unless(commit[0] == 0); + + hangul_ic_reset(ic); + + // insert ㅇ when a syllable is not started with consonant + hangul_ic_process(ic, 'a'); + + preedit = hangul_ic_get_preedit_string(ic); + commit = hangul_ic_get_commit_string(ic); + fail_unless(preedit[0] == 0xc544); // 아 + fail_unless(commit[0] == 0); + + // remove correctly when automatically ㅇ was inserted + hangul_ic_backspace(ic); + + preedit = hangul_ic_get_preedit_string(ic); + commit = hangul_ic_get_commit_string(ic); + fail_unless(preedit[0] == 0); + fail_unless(commit[0] == 0); + + // append ㅡ when a syllable is not ended with vowel + hangul_ic_process(ic, 't'); + hangul_ic_process(ic, 't'); + + preedit = hangul_ic_get_preedit_string(ic); + commit = hangul_ic_get_commit_string(ic); + fail_unless(preedit[0] == 0x314c); // ㅌ + fail_unless(commit[0] == 0xd2b8); // 트 + + // ng makes trailing ㅇ + hangul_ic_reset(ic); + hangul_ic_process(ic, 'g'); + hangul_ic_process(ic, 'a'); + hangul_ic_process(ic, 'n'); + hangul_ic_process(ic, 'g'); + + preedit = hangul_ic_get_preedit_string(ic); + commit = hangul_ic_get_commit_string(ic); + fail_unless(preedit[0] == 0xac15); // 강 + fail_unless(commit[0] == 0); + + // gangi makes 강이 + hangul_ic_process(ic, 'i'); + + preedit = hangul_ic_get_preedit_string(ic); + commit = hangul_ic_get_commit_string(ic); + fail_unless(preedit[0] == 0xc774); // 이 + fail_unless(commit[0] == 0xac15); // 강 + + // nanG makes 난ㄱ + // uppercase makes new syllable + hangul_ic_process(ic, 'n'); + hangul_ic_process(ic, 'a'); + hangul_ic_process(ic, 'n'); + hangul_ic_process(ic, 'G'); + + preedit = hangul_ic_get_preedit_string(ic); + commit = hangul_ic_get_commit_string(ic); + fail_unless(preedit[0] == 0x3131); // ㄱ + fail_unless(commit[0] == 0xb09c); // 난 + + // special operation for x + // x generate ㅈ for leading consonant + hangul_ic_reset(ic); + hangul_ic_process(ic, 'x'); + hangul_ic_process(ic, 'x'); + + preedit = hangul_ic_get_preedit_string(ic); + commit = hangul_ic_get_commit_string(ic); + fail_unless(preedit[0] == 0x3148); // 지 + fail_unless(commit[0] == 0xc988); + + hangul_ic_reset(ic); + hangul_ic_process(ic, 'x'); + hangul_ic_process(ic, 'y'); + + preedit = hangul_ic_get_preedit_string(ic); + commit = hangul_ic_get_commit_string(ic); + fail_unless(preedit[0] == 0xc9c0); // 지 + fail_unless(commit[0] == 0x0); + + // x generate ㄱㅅ for trailing consonant + // and ㅅ will be transferred to next syllable when next input + // character is vowel. + hangul_ic_reset(ic); + hangul_ic_process(ic, 's'); + hangul_ic_process(ic, 'e'); + hangul_ic_process(ic, 'x'); + hangul_ic_process(ic, 'y'); + + preedit = hangul_ic_get_preedit_string(ic); + commit = hangul_ic_get_commit_string(ic); + fail_unless(preedit[0] == 0xc2dc); // 시 + fail_unless(commit[0] == 0xc139); // 섹 + + hangul_ic_delete(ic); +} +END_TEST + START_TEST(test_syllable_iterator) { ucschar str[] = { @@ -123,6 +239,7 @@ Suite* libhangul_suite() Suite* s = suite_create("libhangul"); TCase* hangul = tcase_create("hangul"); + tcase_add_test(hangul, test_hangul_ic_process_romaja); tcase_add_test(hangul, test_syllable_iterator); suite_add_tcase(s, hangul); |