-
Notifications
You must be signed in to change notification settings - Fork 0
/
gowchar_test.go
55 lines (51 loc) · 1.06 KB
/
gowchar_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
package gowchar
import (
"fmt"
"testing"
)
func TestGowcharSimple(t *testing.T) {
str1 := "Привет, 世界. 𪛖"
wstr, size := StringToWcharT(str1)
switch SIZEOF_WCHAR_T {
case 2:
if size != 15 {
t.Errorf("size(%v) != 15", size)
}
case 4:
if size != 14 {
t.Errorf("size(%v) != 14", size)
}
default:
panic(fmt.Sprintf("sizeof(wchar_t) = %v", SIZEOF_WCHAR_T))
}
str2, err := WcharTToString(wstr)
if err != nil {
t.Errorf("WcharTToString error: %v", err)
}
if str1 != str2 {
t.Errorf("\"%s\" != \"%s\"", str1, str2)
}
}
func TestGowcharSimpleN(t *testing.T) {
str1 := "Привет, 世界. 𪛖"
wstr, size := StringToWcharT(str1)
switch SIZEOF_WCHAR_T {
case 2:
if size != 15 {
t.Errorf("size(%v) != 15", size)
}
case 4:
if size != 14 {
t.Errorf("size(%v) != 14", size)
}
default:
panic(fmt.Sprintf("sizeof(wchar_t) = %v", SIZEOF_WCHAR_T))
}
str2, err := WcharTNToString(wstr, size-1)
if err != nil {
t.Errorf("WcharTToString error: %v", err)
}
if str1 != str2 {
t.Errorf("\"%s\" != \"%s\"", str1, str2)
}
}