diff options
author | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2012-01-18 13:39:50 +0000 |
---|---|---|
committer | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2012-01-18 13:39:50 +0000 |
commit | 82ad14175cbcc7c0c660720c7a31f8e6f1cefe4e (patch) | |
tree | 8c20d19ebbf277de41a1d89167576a4b087f6011 /t/03utf8.c | |
parent | 082b49f0f8790e2cf98346a03c53f492d9d5dcba (diff) | |
download | termo-82ad14175cbcc7c0c660720c7a31f8e6f1cefe4e.tar.gz termo-82ad14175cbcc7c0c660720c7a31f8e6f1cefe4e.tar.xz termo-82ad14175cbcc7c0c660720c7a31f8e6f1cefe4e.zip |
Added termkey_push_bytes(), a new API for providing input bytes
Diffstat (limited to 't/03utf8.c')
-rw-r--r-- | t/03utf8.c | 71 |
1 files changed, 23 insertions, 48 deletions
@@ -3,22 +3,18 @@ int main(int argc, char *argv[]) { - int fd[2]; TermKey *tk; TermKeyKey key; plan_tests(57); - pipe(fd); - /* Sanitise this just in case */ putenv("TERM=vt100"); - tk = termkey_new(fd[0], TERMKEY_FLAG_NOTERMIOS|TERMKEY_FLAG_UTF8); + tk = termkey_new(0, TERMKEY_FLAG_NOTERMIOS|TERMKEY_FLAG_UTF8); - write(fd[1], "a", 1); + termkey_push_bytes(tk, "a", 1); - termkey_advisereadable(tk); is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY low ASCII"); is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type low ASCII"); is_int(key.code.number, 'a', "key.code.number low ASCII"); @@ -26,97 +22,85 @@ int main(int argc, char *argv[]) /* 2-byte UTF-8 range is U+0080 to U+07FF (0xDF 0xBF) */ /* However, we'd best avoid the C1 range, so we'll start at U+00A0 (0xC2 0xA0) */ - write(fd[1], "\xC2\xA0", 2); + termkey_push_bytes(tk, "\xC2\xA0", 2); - termkey_advisereadable(tk); is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 2 low"); is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type UTF-8 2 low"); is_int(key.code.number, 0x00A0, "key.code.number UTF-8 2 low"); - write(fd[1], "\xDF\xBF", 2); + termkey_push_bytes(tk, "\xDF\xBF", 2); - termkey_advisereadable(tk); is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 2 high"); is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type UTF-8 2 high"); is_int(key.code.number, 0x07FF, "key.code.number UTF-8 2 high"); /* 3-byte UTF-8 range is U+0800 (0xE0 0xA0 0x80) to U+FFFD (0xEF 0xBF 0xBD) */ - write(fd[1], "\xE0\xA0\x80", 3); + termkey_push_bytes(tk, "\xE0\xA0\x80", 3); - termkey_advisereadable(tk); is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 3 low"); is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type UTF-8 3 low"); is_int(key.code.number, 0x0800, "key.code.number UTF-8 3 low"); - write(fd[1], "\xEF\xBF\xBD", 3); + termkey_push_bytes(tk, "\xEF\xBF\xBD", 3); - termkey_advisereadable(tk); is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 3 high"); is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type UTF-8 3 high"); is_int(key.code.number, 0xFFFD, "key.code.number UTF-8 3 high"); /* 4-byte UTF-8 range is U+10000 (0xF0 0x90 0x80 0x80) to U+10FFFF (0xF4 0x8F 0xBF 0xBF) */ - write(fd[1], "\xF0\x90\x80\x80", 4); + termkey_push_bytes(tk, "\xF0\x90\x80\x80", 4); - termkey_advisereadable(tk); is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 4 low"); is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type UTF-8 4 low"); is_int(key.code.number, 0x10000, "key.code.number UTF-8 4 low"); - write(fd[1], "\xF4\x8F\xBF\xBF", 4); + termkey_push_bytes(tk, "\xF4\x8F\xBF\xBF", 4); - termkey_advisereadable(tk); is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 4 high"); 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_push_bytes(tk, "\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_push_bytes(tk, "\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_push_bytes(tk, "\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_push_bytes(tk, "\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_push_bytes(tk, "\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_push_bytes(tk, "\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"); @@ -124,42 +108,33 @@ int main(int argc, char *argv[]) /* Partials */ - write(fd[1], "\xC2", 1); - termkey_advisereadable(tk); + termkey_push_bytes(tk, "\xC2", 1); 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); + termkey_push_bytes(tk, "\xA0", 1); 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); + termkey_push_bytes(tk, "\xE0", 1); 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); + termkey_push_bytes(tk, "\xA0", 1); 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); + termkey_push_bytes(tk, "\x80", 1); 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); + termkey_push_bytes(tk, "\xF0", 1); 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); + termkey_push_bytes(tk, "\x90", 1); 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); + termkey_push_bytes(tk, "\x80", 1); 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); + termkey_push_bytes(tk, "\x80", 1); 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"); |