diff options
author | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2011-04-02 15:07:30 +0100 |
---|---|---|
committer | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2011-04-02 15:07:30 +0100 |
commit | ad7d31ead8ff9c34bb63172754d3e7d15d803bde (patch) | |
tree | 0d8b179d1d97c74223e117748420f49ef5ca9c38 /t | |
parent | 04683553896358b7c3115fa646f88762ee4a8212 (diff) | |
download | termo-ad7d31ead8ff9c34bb63172754d3e7d15d803bde.tar.gz termo-ad7d31ead8ff9c34bb63172754d3e7d15d803bde.tar.xz termo-ad7d31ead8ff9c34bb63172754d3e7d15d803bde.zip |
Provide termkey_keycmp() for sorting purposes
Diffstat (limited to 't')
-rw-r--r-- | t/13cmpkey.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/t/13cmpkey.c b/t/13cmpkey.c new file mode 100644 index 0000000..75f5ad7 --- /dev/null +++ b/t/13cmpkey.c @@ -0,0 +1,50 @@ +#include "../termkey.h" +#include "taplib.h" + +int main(int argc, char *argv[]) +{ + TermKey *tk; + TermKeyKey key1, key2; + + plan_tests(10); + + tk = termkey_new(0, TERMKEY_FLAG_NOTERMIOS); + + key1.type = TERMKEY_TYPE_UNICODE; + key1.code.codepoint = 'A'; + key1.modifiers = 0; + + is_int(termkey_keycmp(tk, &key1, &key1), 0, "cmpkey same structure"); + + key2.type = TERMKEY_TYPE_UNICODE; + key2.code.codepoint = 'A'; + key2.modifiers = 0; + + is_int(termkey_keycmp(tk, &key1, &key2), 0, "cmpkey identical structure"); + + key2.modifiers = TERMKEY_KEYMOD_CTRL; + + ok(termkey_keycmp(tk, &key1, &key2) > 0, "cmpkey orders CTRL after nomod"); + ok(termkey_keycmp(tk, &key2, &key1) < 0, "cmpkey orders nomod before CTRL"); + + key2.code.codepoint = 'B'; + key2.modifiers = 0; + + ok(termkey_keycmp(tk, &key1, &key2) > 0, "cmpkey orders 'B' after 'A'"); + ok(termkey_keycmp(tk, &key2, &key1) < 0, "cmpkey orders 'A' before 'B'"); + + key1.modifiers = TERMKEY_KEYMOD_CTRL; + + ok(termkey_keycmp(tk, &key1, &key2) > 0, "cmpkey orders nomod 'B' after CTRL 'A'"); + ok(termkey_keycmp(tk, &key2, &key1) < 0, "cmpkey orders CTRL 'A' before nomod 'B'"); + + key2.type = TERMKEY_TYPE_KEYSYM; + key2.code.sym = TERMKEY_SYM_UP; + + ok(termkey_keycmp(tk, &key1, &key2) > 0, "cmpkey orders KEYSYM after UNICODE"); + ok(termkey_keycmp(tk, &key2, &key1) < 0, "cmpkey orders UNICODE before KEYSYM"); + + termkey_destroy(tk); + + return exit_status(); +} |