aboutsummaryrefslogtreecommitdiff
path: root/t/03utf8.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2011-03-31 23:42:52 +0100
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2011-03-31 23:42:52 +0100
commitf1b3dff4c2075d9304dd4c298db433c7d404f3a3 (patch)
tree0705094f83a89c098ce3293edacc6e36c888f7ef /t/03utf8.c
parent739be0e55d1301856ae6e86f85903a7f86b3b878 (diff)
downloadtermo-f1b3dff4c2075d9304dd4c298db433c7d404f3a3.tar.gz
termo-f1b3dff4c2075d9304dd4c298db433c7d404f3a3.tar.xz
termo-f1b3dff4c2075d9304dd4c298db433c7d404f3a3.zip
Extract UTF-8 sequence parser into its own function, fix bugs, apply unit tests
Diffstat (limited to 't/03utf8.c')
-rw-r--r--t/03utf8.c93
1 files changed, 92 insertions, 1 deletions
diff --git a/t/03utf8.c b/t/03utf8.c
index d4d8da3..34fce6f 100644
--- a/t/03utf8.c
+++ b/t/03utf8.c
@@ -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();