test_unmapped.js (2029B)
1 // Tests encoding of unmapped characters 2 const inString = "\uE5E5"; 3 const expectedString = "?"; 4 5 function run_test() { 6 var failures = false; 7 var encodingConverter = CreateScriptableConverter(); 8 9 // this list excludes codepages that can represent all Unicode 10 var encoders = [ 11 "Big5", 12 "EUC-JP", 13 "EUC-KR", 14 "GBK", 15 "gb18030", 16 "IBM866", 17 "ISO-2022-JP", 18 "ISO-8859-3", 19 "ISO-8859-4", 20 "ISO-8859-5", 21 "ISO-8859-6", 22 "ISO-8859-7", 23 "ISO-8859-8", 24 "ISO-8859-8-I", 25 "ISO-8859-10", 26 "ISO-8859-13", 27 "ISO-8859-14", 28 "ISO-8859-15", 29 "ISO-8859-16", 30 "ISO-8859-2", 31 "KOI8-R", 32 "KOI8-U", 33 "Shift_JIS", 34 "windows-1250", 35 "windows-1251", 36 "windows-1252", 37 "windows-1253", 38 "windows-1254", 39 "windows-1255", 40 "windows-1256", 41 "windows-1257", 42 "windows-1258", 43 "windows-874", 44 "x-mac-cyrillic", 45 ]; 46 47 var counter = 0; 48 while (counter < encoders.length) { 49 var charset = encoders[counter++]; 50 51 dump("testing " + counter + " " + charset + "\n"); 52 encodingConverter.charset = charset; 53 var codepageString = 54 encodingConverter.ConvertFromUnicode(inString) + 55 encodingConverter.Finish(); 56 if (codepageString != expectedString) { 57 dump(charset + " encoding failed\n"); 58 for (var i = 0; i < expectedString.length; ++i) { 59 if (i >= codepageString.length) { 60 dump( 61 "output length " + 62 codepageString.length + 63 " less than expected length " + 64 expectedString.length + 65 "\n" 66 ); 67 break; 68 } 69 if (codepageString.charAt(i) != expectedString.charAt(i)) { 70 dump( 71 i.toString(16) + 72 ": 0x" + 73 codepageString.charCodeAt(i).toString(16) + 74 " != " + 75 expectedString.charCodeAt(i).toString(16) + 76 "\n" 77 ); 78 } 79 } 80 failures = true; 81 } 82 } 83 if (failures) { 84 do_throw("test failed\n"); 85 } 86 }