@@ -62,19 +62,24 @@ func TestToUTF8WithErr(t *testing.T) {
62
62
}
63
63
64
64
func TestToUTF8WithFallback (t * testing.T ) {
65
+ // "ABC"
65
66
res := ToUTF8WithFallback ([]byte {0x41 , 0x42 , 0x43 })
66
- assert .Equal (t , []byte ( "ABC" ) , res )
67
+ assert .Equal (t , []byte { 0x41 , 0x42 , 0x43 } , res )
67
68
69
+ // "áéíóú"
68
70
res = ToUTF8WithFallback ([]byte {0xc3 , 0xa1 , 0xc3 , 0xa9 , 0xc3 , 0xad , 0xc3 , 0xb3 , 0xc3 , 0xba })
69
- assert .Equal (t , []byte ( "áéíóú" ) , res )
71
+ assert .Equal (t , []byte { 0xc3 , 0xa1 , 0xc3 , 0xa9 , 0xc3 , 0xad , 0xc3 , 0xb3 , 0xc3 , 0xba } , res )
70
72
73
+ // UTF8 BOM + "áéíóú"
71
74
res = ToUTF8WithFallback ([]byte {0xef , 0xbb , 0xbf , 0xc3 , 0xa1 , 0xc3 , 0xa9 , 0xc3 , 0xad , 0xc3 , 0xb3 , 0xc3 , 0xba })
72
- assert .Equal (t , []byte ( "áéíóú" ) , res )
75
+ assert .Equal (t , []byte { 0xc3 , 0xa1 , 0xc3 , 0xa9 , 0xc3 , 0xad , 0xc3 , 0xb3 , 0xc3 , 0xba } , res )
73
76
77
+ // "Hola, así cómo ños"
74
78
res = ToUTF8WithFallback ([]byte {0x48 , 0x6F , 0x6C , 0x61 , 0x2C , 0x20 , 0x61 , 0x73 , 0xED , 0x20 , 0x63 , 0xF3 , 0x6D , 0x6F , 0x20 , 0xF1 , 0x6F , 0x73 })
75
- assert .Equal (t , []byte ( "Hola, así cómo ños" ) , res )
79
+ assert .Equal (t , []byte { 0x48 , 0x6F , 0x6C , 0x61 , 0x2C , 0x20 , 0x61 , 0x73 , 0xC3 , 0xAD , 0x20 , 0x63 , 0xC3 , 0xB3 , 0x6D , 0x6F , 0x20 , 0xC3 , 0xB1 , 0x6F , 0x73 } , res )
76
80
77
- minmatch := []byte ("Hola, así cómo " )
81
+ // "Hola, así cómo "
82
+ minmatch := []byte {0x48 , 0x6F , 0x6C , 0x61 , 0x2C , 0x20 , 0x61 , 0x73 , 0xC3 , 0xAD , 0x20 , 0x63 , 0xC3 , 0xB3 , 0x6D , 0x6F , 0x20 }
78
83
79
84
res = ToUTF8WithFallback ([]byte {0x48 , 0x6F , 0x6C , 0x61 , 0x2C , 0x20 , 0x61 , 0x73 , 0xED , 0x20 , 0x63 , 0xF3 , 0x6D , 0x6F , 0x20 , 0x07 , 0xA4 , 0x6F , 0x73 })
80
85
// Do not fail for differences in invalid cases, as the library might change the conversion criteria for those
@@ -85,8 +90,10 @@ func TestToUTF8WithFallback(t *testing.T) {
85
90
assert .Equal (t , minmatch , res [0 :len (minmatch )])
86
91
87
92
// Japanese (Shift-JIS)
93
+ // "日属秘ぞしちゅ。"
88
94
res = ToUTF8WithFallback ([]byte {0x93 , 0xFA , 0x91 , 0xAE , 0x94 , 0xE9 , 0x82 , 0xBC , 0x82 , 0xB5 , 0x82 , 0xBF , 0x82 , 0xE3 , 0x81 , 0x42 })
89
- assert .Equal (t , []byte ("日属秘ぞしちゅ。" ), res )
95
+ assert .Equal (t , []byte {0xE6 , 0x97 , 0xA5 , 0xE5 , 0xB1 , 0x9E , 0xE7 , 0xA7 , 0x98 , 0xE3 ,
96
+ 0x81 , 0x9E , 0xE3 , 0x81 , 0x97 , 0xE3 , 0x81 , 0xA1 , 0xE3 , 0x82 , 0x85 , 0xE3 , 0x80 , 0x82 }, res )
90
97
91
98
res = ToUTF8WithFallback ([]byte {0x00 , 0x00 , 0x00 , 0x00 })
92
99
assert .Equal (t , []byte {0x00 , 0x00 , 0x00 , 0x00 }, res )
@@ -124,19 +131,24 @@ func TestToUTF8(t *testing.T) {
124
131
}
125
132
126
133
func TestToUTF8DropErrors (t * testing.T ) {
134
+ // "ABC"
127
135
res := ToUTF8DropErrors ([]byte {0x41 , 0x42 , 0x43 })
128
- assert .Equal (t , []byte ( "ABC" ) , res )
136
+ assert .Equal (t , []byte { 0x41 , 0x42 , 0x43 } , res )
129
137
138
+ // "áéíóú"
130
139
res = ToUTF8DropErrors ([]byte {0xc3 , 0xa1 , 0xc3 , 0xa9 , 0xc3 , 0xad , 0xc3 , 0xb3 , 0xc3 , 0xba })
131
- assert .Equal (t , []byte ( "áéíóú" ) , res )
140
+ assert .Equal (t , []byte { 0xc3 , 0xa1 , 0xc3 , 0xa9 , 0xc3 , 0xad , 0xc3 , 0xb3 , 0xc3 , 0xba } , res )
132
141
142
+ // UTF8 BOM + "áéíóú"
133
143
res = ToUTF8DropErrors ([]byte {0xef , 0xbb , 0xbf , 0xc3 , 0xa1 , 0xc3 , 0xa9 , 0xc3 , 0xad , 0xc3 , 0xb3 , 0xc3 , 0xba })
134
- assert .Equal (t , []byte ( "áéíóú" ) , res )
144
+ assert .Equal (t , []byte { 0xc3 , 0xa1 , 0xc3 , 0xa9 , 0xc3 , 0xad , 0xc3 , 0xb3 , 0xc3 , 0xba } , res )
135
145
146
+ // "Hola, así cómo ños"
136
147
res = ToUTF8DropErrors ([]byte {0x48 , 0x6F , 0x6C , 0x61 , 0x2C , 0x20 , 0x61 , 0x73 , 0xED , 0x20 , 0x63 , 0xF3 , 0x6D , 0x6F , 0x20 , 0xF1 , 0x6F , 0x73 })
137
- assert .Equal (t , []byte ( "Hola, así cómo ños" ) , res )
148
+ assert .Equal (t , []byte { 0x48 , 0x6F , 0x6C , 0x61 , 0x2C , 0x20 , 0x61 , 0x73 , 0xC3 , 0xAD , 0x20 , 0x63 , 0xC3 , 0xB3 , 0x6D , 0x6F , 0x20 , 0xC3 , 0xB1 , 0x6F , 0x73 } , res )
138
149
139
- minmatch := []byte ("Hola, así cómo " )
150
+ // "Hola, así cómo "
151
+ minmatch := []byte {0x48 , 0x6F , 0x6C , 0x61 , 0x2C , 0x20 , 0x61 , 0x73 , 0xC3 , 0xAD , 0x20 , 0x63 , 0xC3 , 0xB3 , 0x6D , 0x6F , 0x20 }
140
152
141
153
res = ToUTF8DropErrors ([]byte {0x48 , 0x6F , 0x6C , 0x61 , 0x2C , 0x20 , 0x61 , 0x73 , 0xED , 0x20 , 0x63 , 0xF3 , 0x6D , 0x6F , 0x20 , 0x07 , 0xA4 , 0x6F , 0x73 })
142
154
// Do not fail for differences in invalid cases, as the library might change the conversion criteria for those
@@ -147,8 +159,10 @@ func TestToUTF8DropErrors(t *testing.T) {
147
159
assert .Equal (t , minmatch , res [0 :len (minmatch )])
148
160
149
161
// Japanese (Shift-JIS)
162
+ // "日属秘ぞしちゅ。"
150
163
res = ToUTF8DropErrors ([]byte {0x93 , 0xFA , 0x91 , 0xAE , 0x94 , 0xE9 , 0x82 , 0xBC , 0x82 , 0xB5 , 0x82 , 0xBF , 0x82 , 0xE3 , 0x81 , 0x42 })
151
- assert .Equal (t , []byte ("日属秘ぞしちゅ。" ), res )
164
+ assert .Equal (t , []byte {0xE6 , 0x97 , 0xA5 , 0xE5 , 0xB1 , 0x9E , 0xE7 , 0xA7 , 0x98 , 0xE3 ,
165
+ 0x81 , 0x9E , 0xE3 , 0x81 , 0x97 , 0xE3 , 0x81 , 0xA1 , 0xE3 , 0x82 , 0x85 , 0xE3 , 0x80 , 0x82 }, res )
152
166
153
167
res = ToUTF8DropErrors ([]byte {0x00 , 0x00 , 0x00 , 0x00 })
154
168
assert .Equal (t , []byte {0x00 , 0x00 , 0x00 , 0x00 }, res )
0 commit comments