diff options
Diffstat (limited to 't')
-rw-r--r-- | t/03utf8.c | 93 |
1 files changed, 92 insertions, 1 deletions
@@ -7,7 +7,7 @@ int main(int argc, char *argv[]) TermKey *tk; TermKeyKey key; - plan_tests(21); + plan_tests(57); pipe(fd); @@ -72,6 +72,97 @@ int main(int argc, char *argv[]) is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type UTF-8 4 high"); is_int(key.code.number, 0x10FFFF, "key.code.number UTF-8 4 high"); + /* Invalid continuations */ + + write(fd[1], "\xC2!", 2); + + termkey_advisereadable(tk); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 2 invalid cont"); + is_int(key.code.number, 0xFFFD, "key.code.number UTF-8 2 invalid cont"); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 2 invalid after"); + is_int(key.code.number, '!', "key.code.number UTF-8 2 invalid after"); + + write(fd[1], "\xE0!", 2); + + termkey_advisereadable(tk); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 3 invalid cont"); + is_int(key.code.number, 0xFFFD, "key.code.number UTF-8 3 invalid cont"); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 3 invalid after"); + is_int(key.code.number, '!', "key.code.number UTF-8 3 invalid after"); + + write(fd[1], "\xE0\xA0!", 3); + + termkey_advisereadable(tk); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 3 invalid cont 2"); + is_int(key.code.number, 0xFFFD, "key.code.number UTF-8 3 invalid cont 2"); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 3 invalid after"); + is_int(key.code.number, '!', "key.code.number UTF-8 3 invalid after"); + + write(fd[1], "\xF0!", 2); + + termkey_advisereadable(tk); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 4 invalid cont"); + is_int(key.code.number, 0xFFFD, "key.code.number UTF-8 4 invalid cont"); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 4 invalid after"); + is_int(key.code.number, '!', "key.code.number UTF-8 4 invalid after"); + + write(fd[1], "\xF0\x90!", 3); + + termkey_advisereadable(tk); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 4 invalid cont 2"); + is_int(key.code.number, 0xFFFD, "key.code.number UTF-8 4 invalid cont 2"); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 4 invalid after"); + is_int(key.code.number, '!', "key.code.number UTF-8 4 invalid after"); + + write(fd[1], "\xF0\x90\x80!", 4); + + termkey_advisereadable(tk); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 4 invalid cont 3"); + is_int(key.code.number, 0xFFFD, "key.code.number UTF-8 4 invalid cont 3"); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 4 invalid after"); + is_int(key.code.number, '!', "key.code.number UTF-8 4 invalid after"); + + /* Partials */ + + write(fd[1], "\xC2", 1); + termkey_advisereadable(tk); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_AGAIN, "getkey yields RES_AGAIN UTF-8 2 partial"); + + write(fd[1], "\xA0", 1); + termkey_advisereadable(tk); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 2 partial"); + is_int(key.code.number, 0x00A0, "key.code.number UTF-8 2 partial"); + + write(fd[1], "\xE0", 1); + termkey_advisereadable(tk); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_AGAIN, "getkey yields RES_AGAIN UTF-8 3 partial"); + + write(fd[1], "\xA0", 1); + termkey_advisereadable(tk); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_AGAIN, "getkey yields RES_AGAIN UTF-8 3 partial"); + + write(fd[1], "\x80", 1); + termkey_advisereadable(tk); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 3 partial"); + is_int(key.code.number, 0x0800, "key.code.number UTF-8 3 partial"); + + write(fd[1], "\xF0", 1); + termkey_advisereadable(tk); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_AGAIN, "getkey yields RES_AGAIN UTF-8 4 partial"); + + write(fd[1], "\x90", 1); + termkey_advisereadable(tk); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_AGAIN, "getkey yields RES_AGAIN UTF-8 4 partial"); + + write(fd[1], "\x80", 1); + termkey_advisereadable(tk); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_AGAIN, "getkey yields RES_AGAIN UTF-8 4 partial"); + + write(fd[1], "\x80", 1); + termkey_advisereadable(tk); + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 4 partial"); + is_int(key.code.number, 0x10000, "key.code.number UTF-8 4 partial"); + termkey_destroy(tk); return exit_status(); |