-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwchar_test.go
105 lines (92 loc) · 2.61 KB
/
wchar_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
98
99
100
101
102
103
104
105
package wchar
import (
"testing"
)
func TestStringConversion(t *testing.T) {
testString := "Iñtërnâtiônàlizætiøn"
expectedWcharString := WcharString{
73, 241, 116, 235, 114,
110, 226, 116, 105, 244,
110, 224, 108, 105, 122,
230, 116, 105, 248, 110, 0,
}
w, err := FromGoString(testString)
if err != nil {
t.Fatalf("Error on conversion. %s", err.Error())
}
if len(w) != len(expectedWcharString) {
t.Fatal("Converted string did not match expected WcharString. Lengths are different.")
}
for i := 0; i < len(w); i++ {
if w[i] != expectedWcharString[i] {
t.Fatalf("Converted string did not match expected WcharString. Fault at position %d. %d!=%d\n", i, w[i], expectedWcharString[i])
}
}
}
func TestWcharStringConversion(t *testing.T) {
testWcharString := WcharString{
73, 241, 116, 235, 114,
110, 226, 116, 105, 244,
110, 224, 108, 105, 122,
230, 116, 105, 248, 110, 0,
}
expectedGoString := "Iñtërnâtiônàlizætiøn"
str, err := testWcharString.GoString()
if err != nil {
t.Fatalf("Error on conversion. %s", err.Error())
}
if len(str) != len(expectedGoString) {
t.Fatal("Converted WcharString did not match expected string. Lengths are different.")
}
for i := 0; i < len(str); i++ {
if str[i] != expectedGoString[i] {
t.Fatalf("Converted WcharString did not match expected string. Fault at position %d. %d!=%d\n", i, str[i], expectedGoString[i])
}
}
}
func TestRuneConversion(t *testing.T) {
testRunes := []rune{
'I', 'ñ', 't', 'ë', 'r',
'n', 'â', 't', 'i', 'ô',
'n', 'à', 'l', 'i', 'z',
'æ', 't', 'i', 'ø', 'n',
}
expectedWchars := []Wchar{
73, 241, 116, 235, 114,
110, 226, 116, 105, 244,
110, 224, 108, 105, 122,
230, 116, 105, 248, 110,
}
for i, testRune := range testRunes {
w, err := FromGoRune(testRune)
if err != nil {
t.Fatalf("Error on conversion. %s", err.Error())
}
if w != expectedWchars[i] {
t.Fatalf("Converted rune did not match expected Wchar. Fault at position %d. %d!=%d\n", i, w, expectedWchars[i])
}
}
}
func TestWcharConversion(t *testing.T) {
testWchars := []Wchar{
73, 241, 116, 235, 114,
110, 226, 116, 105, 244,
110, 224, 108, 105, 122,
230, 116, 105, 248, 110,
}
expectedRunes := []rune{
'I', 'ñ', 't', 'ë', 'r',
'n', 'â', 't', 'i', 'ô',
'n', 'à', 'l', 'i', 'z',
'æ', 't', 'i', 'ø', 'n',
}
for i, testWchar := range testWchars {
r, err := testWchar.GoRune()
if err != nil {
t.Fatalf("Error on conversion. %s", err.Error())
}
if r != expectedRunes[i] {
t.Fatalf("Converted Wchar did not match expected rune. Fault at position %d. %d!=%d\n", i, r, expectedRunes[i])
}
}
}