@@ -9,6 +9,25 @@ import (
99 "testing"
1010)
1111
12+ type envVars struct {
13+ lang string
14+ lc_all string
15+ lc_ctype string
16+ }
17+
18+ func saveEnv () envVars {
19+ return envVars {
20+ lang : os .Getenv ("LANG" ),
21+ lc_all : os .Getenv ("LC_ALL" ),
22+ lc_ctype : os .Getenv ("LC_CTYPE" ),
23+ }
24+ }
25+ func restoreEnv (env * envVars ) {
26+ os .Setenv ("LANG" , env .lang )
27+ os .Setenv ("LC_ALL" , env .lc_all )
28+ os .Setenv ("LC_CTYPE" , env .lc_ctype )
29+ }
30+
1231func TestIsEastAsian (t * testing.T ) {
1332 testcases := []struct {
1433 locale string
@@ -29,8 +48,9 @@ func TestIsEastAsian(t *testing.T) {
2948}
3049
3150func TestIsEastAsianLCCTYPE (t * testing.T ) {
32- lcctype := os .Getenv ("LC_CTYPE" )
33- defer os .Setenv ("LC_CTYPE" , lcctype )
51+ env := saveEnv ()
52+ defer restoreEnv (& env )
53+ os .Setenv ("LC_ALL" , "" )
3454
3555 testcases := []struct {
3656 lcctype string
@@ -52,11 +72,9 @@ func TestIsEastAsianLCCTYPE(t *testing.T) {
5272}
5373
5474func TestIsEastAsianLANG (t * testing.T ) {
55- lcctype := os .Getenv ("LC_CTYPE" )
56- defer os .Setenv ("LC_CTYPE" , lcctype )
57- lang := os .Getenv ("LANG" )
58- defer os .Setenv ("LANG" , lang )
59-
75+ env := saveEnv ()
76+ defer restoreEnv (& env )
77+ os .Setenv ("LC_ALL" , "" )
6078 os .Setenv ("LC_CTYPE" , "" )
6179
6280 testcases := []struct {
0 commit comments