-
Notifications
You must be signed in to change notification settings - Fork 12
/
test.cpp
335 lines (319 loc) · 7.61 KB
/
test.cpp
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#include "wcwidth9.h"
#include "widechar_width.h"
// Return whether 'his' (wcwidth9) width is compatible with 'mine'
// (widechar_width) size.
static bool compatible(int his, int mine) {
switch (mine) {
case widechar_nonprint:
return his == -1;
case widechar_combining:
return his == -1;
case widechar_ambiguous:
return his == -2;
case widechar_private_use:
return his == -3;
case widechar_unassigned:
case widechar_non_character:
return his == -1;
case widechar_widened_in_9:
return his == 1 || his == 2 || his == -2;
default:
return his == mine;
}
}
// Characters that we expect to differ from wcwidth9.
static bool exceptional(int c) {
// Characters new in Unicode 10 or 11
if (widechar_wcwidth(c) != widechar_unassigned &&
wcwidth9_intable(wcwidth9_not_assigned, WCWIDTH9_ARRAY_SIZE(wcwidth9_not_assigned), c)) {
return true;
}
if ((c >= 0x1160 && c <= 0x11FF) || (c >= 0xD7B0 && c <= 0xD7FF)) {
return true;
}
switch (c) {
// Format (Cf) characters which wcwidth9 reports as width 1 but should be
// -1
case 0x600:
case 0x601:
case 0x0602:
case 0x0603:
case 0x0604:
case 0x0605:
case 0x061C:
case 0x06DD:
case 0x08E2:
// wcwidth thinks these two are combining, but they are not.
case 0x1CF2:
case 0x1CF3:
case 0x2060:
case 0x2061:
case 0x2062:
case 0x2063:
case 0x2064:
case 0x2066:
case 0x2067:
case 0x2068:
case 0x2069:
// bitcoin! new in Unicode 10 and 11
case 0x20BF:
case 0x110BD:
case 0x1BCA0:
case 0x1BCA1:
case 0x1BCA2:
case 0x1BCA3:
case 0x1D173:
case 0x1D174:
case 0x1D175:
case 0x1D176:
case 0x1D177:
case 0x1D178:
case 0x1D179:
case 0x1D17A:
// regional indicator symbols.
// EastAsianWidth says these are narrow even though they appear in
// emoji-data.txt. It's a mess.
case 0x1F1E6:
case 0x1F1E7:
case 0x1F1E8:
case 0x1F1E9:
case 0x1F1EA:
case 0x1F1EB:
case 0x1F1EC:
case 0x1F1ED:
case 0x1F1EE:
case 0x1F1EF:
case 0x1F1F0:
case 0x1F1F1:
case 0x1F1F2:
case 0x1F1F3:
case 0x1F1F4:
case 0x1F1F5:
case 0x1F1F6:
case 0x1F1F7:
case 0x1F1F8:
case 0x1F1F9:
case 0x1F1FA:
case 0x1F1FB:
case 0x1F1FC:
case 0x1F1FD:
case 0x1F1FE:
case 0x1F1FF:
// Some more emoji explicitly marked as narrow in EAW.
case 0x1F321:
case 0x1F324:
case 0x1F325:
case 0x1F326:
case 0x1F327:
case 0x1F328:
case 0x1F329:
case 0x1F32A:
case 0x1F32B:
case 0x1F32C:
case 0x1F336:
case 0x1F37D:
case 0x1F396:
case 0x1F397:
case 0x1F399:
case 0x1F39A:
case 0x1F39B:
case 0x1F39E:
case 0x1F39F:
case 0x1F3CB:
case 0x1F3CC:
case 0x1F3CD:
case 0x1F3CE:
case 0x1F3D4:
case 0x1F3D5:
case 0x1F3D6:
case 0x1F3D7:
case 0x1F3D8:
case 0x1F3D9:
case 0x1F3DA:
case 0x1F3DB:
case 0x1F3DC:
case 0x1F3DD:
case 0x1F3DE:
case 0x1F3DF:
case 0x1F3F3:
case 0x1F3F5:
case 0x1F3F7:
case 0x1F43F:
case 0x1F441:
case 0x1F4FD:
case 0x1F549:
case 0x1F54A:
case 0x1F56F:
case 0x1F570:
case 0x1F573:
case 0x1F574:
case 0x1F575:
case 0x1F576:
case 0x1F577:
case 0x1F578:
case 0x1F579:
case 0x1F587:
case 0x1F58A:
case 0x1F58B:
case 0x1F58C:
case 0x1F58D:
case 0x1F590:
case 0x1F5A5:
case 0x1F5A8:
case 0x1F5B1:
case 0x1F5B2:
case 0x1F5BC:
case 0x1F5C2:
case 0x1F5C3:
case 0x1F5C4:
case 0x1F5D1:
case 0x1F5D2:
case 0x1F5D3:
case 0x1F5DC:
case 0x1F5DD:
case 0x1F5DE:
case 0x1F5E1:
case 0x1F5E3:
case 0x1F5E8:
case 0x1F5EF:
case 0x1F5F3:
case 0x1F5FA:
case 0x1F6CB:
case 0x1F6CD:
case 0x1F6CE:
case 0x1F6CF:
case 0x1F6E0:
case 0x1F6E1:
case 0x1F6E2:
case 0x1F6E3:
case 0x1F6E4:
case 0x1F6E5:
case 0x1F6E9:
case 0x1F6F0:
case 0x1F6F3:
case 0x1F93B:
case 0x1F946:
case 0xE0001:
case 0xE0020:
case 0xE0021:
case 0xE0022:
case 0xE0023:
case 0xE0024:
case 0xE0025:
case 0xE0026:
case 0xE0027:
case 0xE0028:
case 0xE0029:
case 0xE002A:
case 0xE002B:
case 0xE002C:
case 0xE002D:
case 0xE002E:
case 0xE002F:
case 0xE0030:
case 0xE0031:
case 0xE0032:
case 0xE0033:
case 0xE0034:
case 0xE0035:
case 0xE0036:
case 0xE0037:
case 0xE0038:
case 0xE0039:
case 0xE003A:
case 0xE003B:
case 0xE003C:
case 0xE003D:
case 0xE003E:
case 0xE003F:
case 0xE0040:
case 0xE0041:
case 0xE0042:
case 0xE0043:
case 0xE0044:
case 0xE0045:
case 0xE0046:
case 0xE0047:
case 0xE0048:
case 0xE0049:
case 0xE004A:
case 0xE004B:
case 0xE004C:
case 0xE004D:
case 0xE004E:
case 0xE004F:
case 0xE0050:
case 0xE0051:
case 0xE0052:
case 0xE0053:
case 0xE0054:
case 0xE0055:
case 0xE0056:
case 0xE0057:
case 0xE0058:
case 0xE0059:
case 0xE005A:
case 0xE005B:
case 0xE005C:
case 0xE005D:
case 0xE005E:
case 0xE005F:
case 0xE0060:
case 0xE0061:
case 0xE0062:
case 0xE0063:
case 0xE0064:
case 0xE0065:
case 0xE0066:
case 0xE0067:
case 0xE0068:
case 0xE0069:
case 0xE006A:
case 0xE006B:
case 0xE006C:
case 0xE006D:
case 0xE006E:
case 0xE006F:
case 0xE0070:
case 0xE0071:
case 0xE0072:
case 0xE0073:
case 0xE0074:
case 0xE0075:
case 0xE0076:
case 0xE0077:
case 0xE0078:
case 0xE0079:
case 0xE007A:
case 0xE007B:
case 0xE007C:
case 0xE007D:
case 0xE007E:
case 0xE007F:
// This appears to have changed category from Po to Mn
case 0x111C9:
// Some unassigneds.
case 0x10FFFE:
case 0x10FFFF:
return true;
}
return false;
}
int run_tests(void) {
int ret = 0;
int max_cp = 0x10FFFF;
for (int c = 0; c <= max_cp; c++) {
auto w1 = wcwidth9(c);
auto w2 = widechar_wcwidth(c);
if (compatible(w1, w2) || exceptional(c)) continue;
printf("%04X: his %d, mine %d, system: %d\n", c, w1, w2, wcwidth(c));
ret = EXIT_FAILURE;
}
return ret;
}
int main(void) {
int ret = 0;
ret |= run_tests();
printf("Tests %s\n", ret == EXIT_SUCCESS ? "passed" : "failed");
return ret;
}