-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_wcwidth.odin
53 lines (42 loc) · 1.15 KB
/
test_wcwidth.odin
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
package wcwidth
import "core:fmt"
tests_run, test_failures: int
assert_width :: proc(expected_width: int, r: rune) {
tests_run += 1
actual_width := wcwidth(r)
if actual_width != expected_width {
fmt.printf(
"ERROR: wcwidth(U+%04x) returned %d, expected %d\n",
r,
actual_width,
expected_width,
)
test_failures += 1
}
}
main :: proc() {
assert_width(1, 'a')
assert_width(1, 'ö')
// Some wide:
assert_width(2, 'A')
assert_width(2, 'B')
assert_width(2, 'C')
assert_width(2, '中')
assert_width(2, '文')
assert_width(2, 0x679C)
assert_width(2, 0x679D)
assert_width(2, 0x2070E)
assert_width(2, 0x20731)
assert_width(1, 0x11A3)
assert_width(2, 0x1F428) // Koala emoji.
assert_width(2, 0x231a) // Watch emoji.
japanese := "コンニチハ"
fmt.println(japanese, "len =", wcswidth(japanese))
mixed := "つのだ⭐HIRO"
fmt.println(mixed, "len =", wcswidth(mixed))
// truncate test
t_size : = 5
fmt.printf("truncate japanese to visible size %d: %s\n", t_size, truncate(japanese, t_size, "..."))
if test_failures > 0 do fmt.printf("%d tests FAILED, ", test_failures)
fmt.printf("%d tests OK\n", tests_run - test_failures)
}