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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
#include "../termo.h"
#include "taplib.h"
int
main (int argc, char *argv[])
{
(void) argc;
(void) argv;
termo_t *tk;
termo_key_t key;
plan_tests (33 /* 57 */);
tk = termo_new_abstract ("vt100", "UTF-8", 0);
termo_push_bytes (tk, "a", 1);
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY low ASCII");
is_int (key.type, TERMO_TYPE_KEY, "key.type low ASCII");
is_int (key.code.codepoint, 'a', "key.code.codepoint low ASCII");
// 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)
termo_push_bytes (tk, "\xC2\xA0", 2);
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 2 low");
is_int (key.type, TERMO_TYPE_KEY, "key.type UTF-8 2 low");
is_int (key.code.codepoint, 0x00A0, "key.code.codepoint UTF-8 2 low");
termo_push_bytes (tk, "\xDF\xBF", 2);
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 2 high");
is_int (key.type, TERMO_TYPE_KEY, "key.type UTF-8 2 high");
is_int (key.code.codepoint, 0x07FF, "key.code.codepoint UTF-8 2 high");
// 3-byte UTF-8 range is U+0800 (0xE0 0xA0 0x80) to U+FFFD (0xEF 0xBF 0xBD)
termo_push_bytes (tk, "\xE0\xA0\x80", 3);
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 3 low");
is_int (key.type, TERMO_TYPE_KEY, "key.type UTF-8 3 low");
is_int (key.code.codepoint, 0x0800, "key.code.codepoint UTF-8 3 low");
termo_push_bytes (tk, "\xEF\xBF\xBD", 3);
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 3 high");
is_int (key.type, TERMO_TYPE_KEY, "key.type UTF-8 3 high");
is_int (key.code.codepoint, 0xFFFD, "key.code.codepoint UTF-8 3 high");
// 4-byte UTF-8 range is U+10000 (0xF0 0x90 0x80 0x80) to U+10FFFF (0xF4 0x8F 0xBF 0xBF)
termo_push_bytes (tk, "\xF0\x90\x80\x80", 4);
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 4 low");
is_int (key.type, TERMO_TYPE_KEY, "key.type UTF-8 4 low");
is_int (key.code.codepoint, 0x10000, "key.code.codepoint UTF-8 4 low");
termo_push_bytes (tk, "\xF4\x8F\xBF\xBF", 4);
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 4 high");
is_int (key.type, TERMO_TYPE_KEY, "key.type UTF-8 4 high");
is_int (key.code.codepoint, 0x10FFFF, "key.code.codepoint UTF-8 4 high");
#if 0
// XXX: With the move to iconv, this has changed significantly.
// Invalid continuations
termo_push_bytes (tk, "\xC2!", 2);
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 2 invalid cont");
is_int (key.code.codepoint, 0xFFFD,
"key.code.codepoint UTF-8 2 invalid cont");
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 2 invalid after");
is_int (key.code.codepoint, '!',
"key.code.codepoint UTF-8 2 invalid after");
termo_push_bytes (tk, "\xE0!", 2);
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 3 invalid cont");
is_int (key.code.codepoint, 0xFFFD,
"key.code.codepoint UTF-8 3 invalid cont");
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 3 invalid after");
is_int (key.code.codepoint, '!',
"key.code.codepoint UTF-8 3 invalid after");
termo_push_bytes (tk, "\xE0\xA0!", 3);
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 3 invalid cont 2");
is_int (key.code.codepoint, 0xFFFD,
"key.code.codepoint UTF-8 3 invalid cont 2");
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 3 invalid after");
is_int (key.code.codepoint, '!',
"key.code.codepoint UTF-8 3 invalid after");
termo_push_bytes (tk, "\xF0!", 2);
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 4 invalid cont");
is_int (key.code.codepoint, 0xFFFD,
"key.code.codepoint UTF-8 4 invalid cont");
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 4 invalid after");
is_int (key.code.codepoint, '!',
"key.code.codepoint UTF-8 4 invalid after");
termo_push_bytes (tk, "\xF0\x90!", 3);
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 4 invalid cont 2");
is_int (key.code.codepoint, 0xFFFD,
"key.code.codepoint UTF-8 4 invalid cont 2");
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 4 invalid after");
is_int (key.code.codepoint, '!',
"key.code.codepoint UTF-8 4 invalid after");
termo_push_bytes (tk, "\xF0\x90\x80!", 4);
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 4 invalid cont 3");
is_int (key.code.codepoint, 0xFFFD,
"key.code.codepoint UTF-8 4 invalid cont 3");
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 4 invalid after");
is_int (key.code.codepoint, '!',
"key.code.codepoint UTF-8 4 invalid after");
#endif
// Partials
termo_push_bytes (tk, "\xC2", 1);
is_int (termo_getkey (tk, &key), TERMO_RES_AGAIN,
"getkey yields RES_AGAIN UTF-8 2 partial");
termo_push_bytes (tk, "\xA0", 1);
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 2 partial");
is_int (key.code.codepoint, 0x00A0,
"key.code.codepoint UTF-8 2 partial");
termo_push_bytes (tk, "\xE0", 1);
is_int (termo_getkey (tk, &key), TERMO_RES_AGAIN,
"getkey yields RES_AGAIN UTF-8 3 partial");
termo_push_bytes (tk, "\xA0", 1);
is_int (termo_getkey (tk, &key), TERMO_RES_AGAIN,
"getkey yields RES_AGAIN UTF-8 3 partial");
termo_push_bytes (tk, "\x80", 1);
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 3 partial");
is_int (key.code.codepoint, 0x0800,
"key.code.codepoint UTF-8 3 partial");
termo_push_bytes (tk, "\xF0", 1);
is_int (termo_getkey (tk, &key), TERMO_RES_AGAIN,
"getkey yields RES_AGAIN UTF-8 4 partial");
termo_push_bytes (tk, "\x90", 1);
is_int (termo_getkey (tk, &key), TERMO_RES_AGAIN,
"getkey yields RES_AGAIN UTF-8 4 partial");
termo_push_bytes (tk, "\x80", 1);
is_int (termo_getkey (tk, &key), TERMO_RES_AGAIN,
"getkey yields RES_AGAIN UTF-8 4 partial");
termo_push_bytes (tk, "\x80", 1);
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
"getkey yields RES_KEY UTF-8 4 partial");
is_int (key.code.codepoint, 0x10000,
"key.code.codepoint UTF-8 4 partial");
termo_destroy (tk);
return exit_status ();
}
|