-
-
Notifications
You must be signed in to change notification settings - Fork 94
/
runewidth_posix_test.go
97 lines (85 loc) · 1.76 KB
/
runewidth_posix_test.go
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
//go:build !windows && !js && !appengine
// +build !windows,!js,!appengine
package runewidth
import (
"os"
"testing"
)
type envVars struct {
lang string
lcall string
lcctype string
}
func saveEnv() envVars {
return envVars{
lang: os.Getenv("LANG"),
lcall: os.Getenv("LC_ALL"),
lcctype: os.Getenv("LC_CTYPE"),
}
}
func restoreEnv(env *envVars) {
os.Setenv("LANG", env.lang)
os.Setenv("LC_ALL", env.lcall)
os.Setenv("LC_CTYPE", env.lcctype)
}
func TestIsEastAsian(t *testing.T) {
testcases := []struct {
locale string
want bool
}{
{"foo@cjk_narrow", false},
{"foo@cjk", false},
{"utf-8@cjk", false},
{"ja_JP.CP932", true},
}
for _, tt := range testcases {
got := isEastAsian(tt.locale)
if got != tt.want {
t.Fatalf("isEastAsian(%q) should be %v", tt.locale, tt.want)
}
}
}
func TestIsEastAsianLCCTYPE(t *testing.T) {
env := saveEnv()
defer restoreEnv(&env)
os.Setenv("LC_ALL", "")
testcases := []struct {
lcctype string
want bool
}{
{"ja_JP.UTF-8", true},
{"C", false},
{"POSIX", false},
{"en_US.UTF-8", false},
}
for _, tt := range testcases {
os.Setenv("LC_CTYPE", tt.lcctype)
got := IsEastAsian()
if got != tt.want {
t.Fatalf("IsEastAsian() for LC_CTYPE=%v should be %v", tt.lcctype, tt.want)
}
}
}
func TestIsEastAsianLANG(t *testing.T) {
env := saveEnv()
defer restoreEnv(&env)
os.Setenv("LC_ALL", "")
os.Setenv("LC_CTYPE", "")
testcases := []struct {
lcctype string
want bool
}{
{"ja_JP.UTF-8", true},
{"C", false},
{"POSIX", false},
{"en_US.UTF-8", false},
{"C.UTF-8", false},
}
for _, tt := range testcases {
os.Setenv("LANG", tt.lcctype)
got := IsEastAsian()
if got != tt.want {
t.Fatalf("IsEastAsian() for LANG=%v should be %v", tt.lcctype, tt.want)
}
}
}