aboutsummaryrefslogtreecommitdiff
path: root/t/12strpkey.c
blob: 648e1c17ffd068f2ca8a8cc3cddcb2b780d975fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "../termkey.h"
#include "taplib.h"

int main(int argc, char *argv[])
{
  TermKey      *tk;
  TermKeyKey    key;
  TermKeyResult res;

#define CLEAR_KEY do { key.type = -1; key.code.number = -1; key.modifiers = -1; key.utf8[0] = 0; } while(0)

  plan_tests(44);

  tk = termkey_new(0, TERMKEY_FLAG_NOTERMIOS);

  CLEAR_KEY;
  res = termkey_strpkey(tk, "A", &key, 0);
  is_int(res, TERMKEY_RES_KEY, "result for unicode/A/0");
  is_int(key.type,        TERMKEY_TYPE_UNICODE, "key.type for unicode/A/0");
  is_int(key.code.number, 'A',                  "key.code.number for unicode/A/0");
  is_int(key.modifiers,   0,                    "key.modifiers for unicode/A/0");
  is_str(key.utf8,        "A",                  "key.utf8 for unicode/A/0");

  CLEAR_KEY;
  res = termkey_strpkey(tk, "C-b", &key, 0);
  is_int(res, TERMKEY_RES_KEY, "result for unicode/b/CTRL");
  is_int(key.type,        TERMKEY_TYPE_UNICODE, "key.type for unicode/b/CTRL");
  is_int(key.code.number, 'b',                  "key.code.number for unicode/b/CTRL");
  is_int(key.modifiers,   TERMKEY_KEYMOD_CTRL,  "key.modifiers for unicode/b/CTRL");
  is_str(key.utf8,        "b",                  "key.utf8 for unicode/b/CTRL");

  CLEAR_KEY;
  res = termkey_strpkey(tk, "Ctrl-b", &key, TERMKEY_FORMAT_LONGMOD);
  is_int(res, TERMKEY_RES_KEY, "result for unicode/b/CTRL longmod");
  is_int(key.type,        TERMKEY_TYPE_UNICODE, "key.type for unicode/b/CTRL longmod");
  is_int(key.code.number, 'b',                  "key.code.number for unicode/b/CTRL longmod");
  is_int(key.modifiers,   TERMKEY_KEYMOD_CTRL,  "key.modifiers for unicode/b/CTRL longmod");
  is_str(key.utf8,        "b",                  "key.utf8 for unicode/b/CTRL longmod");

  CLEAR_KEY;
  res = termkey_strpkey(tk, "^B", &key, TERMKEY_FORMAT_CARETCTRL);
  is_int(res, TERMKEY_RES_KEY, "result for unicode/b/CTRL caretctrl");
  is_int(key.type,        TERMKEY_TYPE_UNICODE, "key.type for unicode/b/CTRL caretctrl");
  is_int(key.code.number, 'b',                  "key.code.number for unicode/b/CTRL caretctrl");
  is_int(key.modifiers,   TERMKEY_KEYMOD_CTRL,  "key.modifiers for unicode/b/CTRL caretctrl");
  is_str(key.utf8,        "b",                  "key.utf8 for unicode/b/CTRL caretctrl");

  CLEAR_KEY;
  res = termkey_strpkey(tk, "A-c", &key, 0);
  is_int(res, TERMKEY_RES_KEY, "result for unicode/c/ALT");
  is_int(key.type,        TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT");
  is_int(key.code.number, 'c',                  "key.code.number for unicode/c/ALT");
  is_int(key.modifiers,   TERMKEY_KEYMOD_ALT,   "key.modifiers for unicode/c/ALT");
  is_str(key.utf8,        "c",                  "key.utf8 for unicode/c/ALT");

  CLEAR_KEY;
  res = termkey_strpkey(tk, "Alt-c", &key, TERMKEY_FORMAT_LONGMOD);
  is_int(res, TERMKEY_RES_KEY, "result for unicode/c/ALT longmod");
  is_int(key.type,        TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT longmod");
  is_int(key.code.number, 'c',                  "key.code.number for unicode/c/ALT longmod");
  is_int(key.modifiers,   TERMKEY_KEYMOD_ALT,   "key.modifiers for unicode/c/ALT longmod");
  is_str(key.utf8,        "c",                  "key.utf8 for unicode/c/ALT longmod");

  CLEAR_KEY;
  res = termkey_strpkey(tk, "M-c", &key, TERMKEY_FORMAT_ALTISMETA);
  is_int(res, TERMKEY_RES_KEY, "result for unicode/c/ALT altismeta");
  is_int(key.type,        TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT altismeta");
  is_int(key.code.number, 'c',                  "key.code.number for unicode/c/ALT altismeta");
  is_int(key.modifiers,   TERMKEY_KEYMOD_ALT,   "key.modifiers for unicode/c/ALT altismeta");
  is_str(key.utf8,        "c",                  "key.utf8 for unicode/c/ALT altismeta");

  CLEAR_KEY;
  res = termkey_strpkey(tk, "Meta-c", &key, TERMKEY_FORMAT_ALTISMETA|TERMKEY_FORMAT_LONGMOD);
  is_int(res, TERMKEY_RES_KEY, "result for unicode/c/ALT altismeta+longmod");
  is_int(key.type,        TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT altismeta+longmod");
  is_int(key.code.number, 'c',                  "key.code.number for unicode/c/ALT altismeta+longmod");
  is_int(key.modifiers,   TERMKEY_KEYMOD_ALT,   "key.modifiers for unicode/c/ALT altismeta+longmod");
  is_str(key.utf8,        "c",                  "key.utf8 for unicode/c/ALT altismeta+longmod");

  CLEAR_KEY;
  res = termkey_strpkey(tk, "Up", &key, 0);
  is_int(res, TERMKEY_RES_KEY, "result for sym/Up/0");
  is_int(key.type,        TERMKEY_TYPE_KEYSYM, "key.type for sym/Up/0");
  is_int(key.code.sym,    TERMKEY_SYM_UP,      "key.code.number for sym/Up/0");
  is_int(key.modifiers,   0,                   "key.modifiers for sym/Up/0");

  termkey_destroy(tk);

  return exit_status();
}