-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwidth_test.go
More file actions
76 lines (69 loc) · 1.2 KB
/
Copy pathwidth_test.go
File metadata and controls
76 lines (69 loc) · 1.2 KB
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
package headlessterm
import (
"testing"
)
func TestRuneWidth(t *testing.T) {
tests := []struct {
r rune
expected int
}{
{'A', 1},
{'a', 1},
{'1', 1},
{' ', 1},
{'中', 2},
{'日', 2},
{'本', 2},
{'한', 2},
{'글', 2},
{'가', 2},
{'A', 2}, // Fullwidth A
{0, 0},
}
for _, tt := range tests {
got := runeWidth(tt.r)
if got != tt.expected {
t.Errorf("runeWidth(%q) = %d, want %d", tt.r, got, tt.expected)
}
}
}
func TestIsWideRune(t *testing.T) {
tests := []struct {
r rune
expected bool
}{
{'A', false},
{'a', false},
{' ', false},
{'中', true},
{'日', true},
{'한', true},
{'가', true},
{'A', true}, // Fullwidth A
{'0', false},
}
for _, tt := range tests {
got := isWideRune(tt.r)
if got != tt.expected {
t.Errorf("isWideRune(%q) = %v, want %v", tt.r, got, tt.expected)
}
}
}
func TestStringWidth(t *testing.T) {
tests := []struct {
s string
expected int
}{
{"Hello", 5},
{"中文", 4},
{"Hello中文", 9},
{"", 0},
{"한글", 4},
}
for _, tt := range tests {
got := StringWidth(tt.s)
if got != tt.expected {
t.Errorf("StringWidth(%q) = %d, want %d", tt.s, got, tt.expected)
}
}
}