@@ -178,6 +178,18 @@ describe('Common implementation mistakes', () => {
178178 } )
179179 } )
180180
181+ // Node.js misses an implementation
182+ test ( 'x-user-defined' , ( t ) => {
183+ const encoding = 'x-user-defined'
184+ const loose = new TextDecoder ( encoding )
185+ const fatal = new TextDecoder ( encoding , { fatal : true } )
186+ for ( let byte = 0 ; byte < 256 ; byte ++ ) {
187+ const str = String . fromCodePoint ( byte >= 0x80 ? 0xf7_80 + byte - 0x80 : byte )
188+ t . assert . strictEqual ( fatal . decode ( Uint8Array . of ( byte ) ) , str , byte )
189+ t . assert . strictEqual ( loose . decode ( Uint8Array . of ( byte ) ) , str , byte )
190+ }
191+ } )
192+
181193 test ( 'big5' , ( t ) => {
182194 const loose = new TextDecoder ( 'big5' )
183195 const fatal = new TextDecoder ( 'big5' , { fatal : true } )
@@ -196,6 +208,46 @@ describe('Common implementation mistakes', () => {
196208 }
197209 } )
198210
211+ describe ( 'single-byte selected tests' , ( t ) => {
212+ const r = 0xff_fd
213+ const fixtures = {
214+ // Node.js fails these (iconv-lite / whatwg-encoding also fails some)
215+ 'koi8-u' : { 174 : 1118 , 190 : 1038 } ,
216+ 'windows-874' : { 129 : 129 , 219 : r , 220 : r , 221 : r , 222 : r , 252 : r , 253 : r , 254 : r , 255 : r } ,
217+ 'windows-1252' : { 128 : 8364 , 129 : 129 , 130 : 8218 , 131 : 402 , 141 : 141 , 158 : 382 , 159 : 376 } ,
218+ 'windows-1253' : { 129 : 129 , 136 : 136 , 159 : 159 , 170 : r } ,
219+ 'windows-1255' : { 129 : 129 , 138 : 138 , 159 : 159 , 202 : 1466 } ,
220+ // iconv-lite / whatwg-encoding fails these
221+ macintosh : { 189 : 937 , 219 : 8364 , 240 : 63_743 } ,
222+ 'windows-1250' : { 129 : 129 , 131 : 131 , 136 : 136 , 144 : 144 , 152 : 152 } ,
223+ 'windows-1251' : { 152 : 152 } ,
224+ 'windows-1254' : { 129 : 129 , 140 : 338 , 141 : 141 , 144 : 144 , 157 : 157 , 158 : 158 , 222 : 350 } ,
225+ 'windows-1257' : { 129 : 129 , 131 : 131 , 138 : 138 , 145 : 8216 , 159 : 159 , 208 : 352 , 255 : 729 } ,
226+ 'windows-1258' : { 129 : 129 , 138 : 138 , 141 : 141 , 158 : 158 , 159 : 376 , 208 : 272 , 255 : 255 } ,
227+ // Some impls miss some encodings
228+ 'iso-8859-8-i' : { 160 : 160 , 161 : r , 162 : 162 , 222 : r , 223 : 8215 , 254 : 8207 , 255 : r } ,
229+ 'iso-8859-16' : { 128 : 128 , 160 : 160 , 161 : 260 , 252 : 252 , 253 : 281 , 254 : 539 , 255 : 255 } ,
230+ 'x-mac-cyrillic' : { 128 : 1040 , 214 : 247 , 254 : 1102 , 255 : 8364 } ,
231+ }
232+
233+ for ( const [ encoding , map ] of Object . entries ( fixtures ) ) {
234+ test ( encoding , ( t ) => {
235+ const fatal = new TextDecoder ( encoding , { fatal : true } )
236+ const loose = new TextDecoder ( encoding )
237+ for ( const [ offset , codepoint ] of Object . entries ( map ) ) {
238+ const u8 = Uint8Array . of ( Number ( offset ) )
239+ const str = String . fromCodePoint ( codepoint )
240+ t . assert . strictEqual ( loose . decode ( u8 ) , str , `${ offset } -> ${ codepoint } ` )
241+ if ( codepoint === r ) {
242+ t . assert . throws ( ( ) => fatal . decode ( u8 ) )
243+ } else {
244+ t . assert . strictEqual ( fatal . decode ( u8 ) , str , `${ offset } -> ${ codepoint } (fatal)` )
245+ }
246+ }
247+ } )
248+ }
249+ } )
250+
199251 // Chrome and WebKit fail at this, Firefox passes
200252 // This one might be tricky to get into WPT, as two major impls ignore spec here
201253 // https://github.com/whatwg/encoding/issues/115
0 commit comments