@@ -62,19 +62,24 @@ func TestToUTF8WithErr(t *testing.T) {
6262}
6363
6464func TestToUTF8WithFallback (t * testing.T ) {
65+ // "ABC"
6566 res := ToUTF8WithFallback ([]byte {0x41 , 0x42 , 0x43 })
66- assert .Equal (t , []byte ( "ABC" ) , res )
67+ assert .Equal (t , []byte { 0x41 , 0x42 , 0x43 } , res )
6768
69+ // "áéíóú"
6870 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 )
7072
73+ // UTF8 BOM + "áéíóú"
7174 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 )
7376
77+ // "Hola, así cómo ños"
7478 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 )
7680
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 }
7883
7984 res = ToUTF8WithFallback ([]byte {0x48 , 0x6F , 0x6C , 0x61 , 0x2C , 0x20 , 0x61 , 0x73 , 0xED , 0x20 , 0x63 , 0xF3 , 0x6D , 0x6F , 0x20 , 0x07 , 0xA4 , 0x6F , 0x73 })
8085 // 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) {
8590 assert .Equal (t , minmatch , res [0 :len (minmatch )])
8691
8792 // Japanese (Shift-JIS)
93+ // "日属秘ぞしちゅ。"
8894 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 )
9097
9198 res = ToUTF8WithFallback ([]byte {0x00 , 0x00 , 0x00 , 0x00 })
9299 assert .Equal (t , []byte {0x00 , 0x00 , 0x00 , 0x00 }, res )
@@ -124,19 +131,24 @@ func TestToUTF8(t *testing.T) {
124131}
125132
126133func TestToUTF8DropErrors (t * testing.T ) {
134+ // "ABC"
127135 res := ToUTF8DropErrors ([]byte {0x41 , 0x42 , 0x43 })
128- assert .Equal (t , []byte ( "ABC" ) , res )
136+ assert .Equal (t , []byte { 0x41 , 0x42 , 0x43 } , res )
129137
138+ // "áéíóú"
130139 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 )
132141
142+ // UTF8 BOM + "áéíóú"
133143 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 )
135145
146+ // "Hola, así cómo ños"
136147 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 )
138149
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 }
140152
141153 res = ToUTF8DropErrors ([]byte {0x48 , 0x6F , 0x6C , 0x61 , 0x2C , 0x20 , 0x61 , 0x73 , 0xED , 0x20 , 0x63 , 0xF3 , 0x6D , 0x6F , 0x20 , 0x07 , 0xA4 , 0x6F , 0x73 })
142154 // 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) {
147159 assert .Equal (t , minmatch , res [0 :len (minmatch )])
148160
149161 // Japanese (Shift-JIS)
162+ // "日属秘ぞしちゅ。"
150163 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 )
152166
153167 res = ToUTF8DropErrors ([]byte {0x00 , 0x00 , 0x00 , 0x00 })
154168 assert .Equal (t , []byte {0x00 , 0x00 , 0x00 , 0x00 }, res )
0 commit comments