-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_linux_test.go
53 lines (47 loc) · 1.07 KB
/
main_linux_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
package mbcs_test
import (
"bytes"
"os"
"testing"
"github.com/nyaosorg/go-windows-mbcs"
)
func TestAnsiToUtf8onAcpLinux(t *testing.T) {
ansi, utf8expect := loadTestdata(t)
origLang, okLang := os.LookupEnv("LC_ALL")
os.Setenv("LC_ALL", "C.Shift_JIS")
//os.Setenv("LANG", "C.EUC-JP")
defer func() {
if okLang {
os.Setenv("LC_ALL", origLang)
} else {
os.Unsetenv("LC_ALL")
}
}()
utf8result, err := mbcs.AnsiToUtf8(ansi, mbcs.ACP)
if err != nil {
t.Fatal(err.Error())
}
if utf8expect != utf8result {
t.Fatalf("expect %#v but %#v", utf8expect, utf8result)
}
}
func TestUtf8ToAnsiAcpOnLinux(t *testing.T) {
ansiExpect, utf8 := loadTestdata(t)
origLang, okLang := os.LookupEnv("LC_ALL")
os.Setenv("LC_ALL", "C.Shift_JIS")
//os.Setenv("LANG", "C.EUC-JP")
defer func() {
if okLang {
os.Setenv("LC_ALL", origLang)
} else {
os.Unsetenv("LC_ALL")
}
}()
ansiResult, err := mbcs.Utf8ToAnsi(utf8, mbcs.ACP)
if err != nil {
t.Fatal(err.Error())
}
if !bytes.Equal(ansiExpect, ansiResult) {
t.Fatalf("expect %#v but %#v", ansiExpect, ansiResult)
}
}