11cb0ef41Sopenharmony_ci// META: title=Encoding API: Encoding labels 21cb0ef41Sopenharmony_ci// META: script=resources/encodings.js 31cb0ef41Sopenharmony_ci// META: timeout=long 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_civar whitespace = [' ', '\t', '\n', '\f', '\r']; 61cb0ef41Sopenharmony_ciencodings_table.forEach(function(section) { 71cb0ef41Sopenharmony_ci section.encodings.filter(function(encoding) { 81cb0ef41Sopenharmony_ci return encoding.name !== 'replacement'; 91cb0ef41Sopenharmony_ci }).forEach(function(encoding) { 101cb0ef41Sopenharmony_ci encoding.labels.forEach(function(label) { 111cb0ef41Sopenharmony_ci const textDecoderName = encoding.name.toLowerCase(); // ASCII names only, so safe 121cb0ef41Sopenharmony_ci test(function(t) { 131cb0ef41Sopenharmony_ci assert_equals( 141cb0ef41Sopenharmony_ci new TextDecoder(label).encoding, textDecoderName, 151cb0ef41Sopenharmony_ci 'label for encoding should match'); 161cb0ef41Sopenharmony_ci assert_equals( 171cb0ef41Sopenharmony_ci new TextDecoder(label.toUpperCase()).encoding, textDecoderName, 181cb0ef41Sopenharmony_ci 'label matching should be case-insensitive'); 191cb0ef41Sopenharmony_ci whitespace.forEach(function(ws) { 201cb0ef41Sopenharmony_ci assert_equals( 211cb0ef41Sopenharmony_ci new TextDecoder(ws + label).encoding, textDecoderName, 221cb0ef41Sopenharmony_ci 'label for encoding with leading whitespace should match'); 231cb0ef41Sopenharmony_ci assert_equals( 241cb0ef41Sopenharmony_ci new TextDecoder(label + ws).encoding, textDecoderName, 251cb0ef41Sopenharmony_ci 'label for encoding with trailing whitespace should match'); 261cb0ef41Sopenharmony_ci assert_equals( 271cb0ef41Sopenharmony_ci new TextDecoder(ws + label + ws).encoding, textDecoderName, 281cb0ef41Sopenharmony_ci 'label for encoding with surrounding whitespace should match'); 291cb0ef41Sopenharmony_ci }); 301cb0ef41Sopenharmony_ci }, label + ' => ' + encoding.name); 311cb0ef41Sopenharmony_ci }); 321cb0ef41Sopenharmony_ci }); 331cb0ef41Sopenharmony_ci}); 34