OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../../../resources/js-test.js"></script> | 2 <title>Encoding API: ASCII supersets</title> |
| 3 <script src="../../../resources/testharness.js"></script> |
| 4 <script src="../../../resources/testharnessreport.js"></script> |
3 <script src="resources/shared.js"></script> | 5 <script src="resources/shared.js"></script> |
4 <script> | 6 <script> |
5 | 7 |
6 description("Supersets of ASCII decode ASCII correctly"); | |
7 | |
8 // Encodings that have escape codes in 0x00-0x7F | 8 // Encodings that have escape codes in 0x00-0x7F |
9 var escape_codes = { | 9 var escape_codes = { |
10 "hz-gb-2312": [ 0x7E ], | 10 'hz-gb-2312': [ 0x7E ], |
11 "iso-2022-jp": [ 0x1B ], | 11 'iso-2022-jp': [ 0x1B ], |
12 "iso-2022-kr": [ 0x0E, 0x0F, 0x1B ] | 12 'iso-2022-kr': [ 0x0E, 0x0F, 0x1B ] |
13 }; | 13 }; |
14 | 14 |
15 encodings_table.forEach(function(section) { | 15 encodings_table.forEach(function(section) { |
16 section.encodings.forEach(function(encoding) { | 16 section.encodings.forEach(function(encoding) { |
17 if (encoding.name === "replacement") | 17 if (encoding.name === 'replacement') |
18 return; | 18 return; |
19 if (utf_encodings.indexOf(encoding.name) !== -1) | 19 if (utf_encodings.indexOf(encoding.name) !== -1) |
20 return; | 20 return; |
21 | 21 |
22 string = ''; | 22 test(function() { |
23 decoded = null; | 23 var string = ''; |
24 bytes = []; | 24 var bytes = []; |
25 for (var i = 0; i < 128; ++i) { | 25 for (var i = 0; i < 128; ++i) { |
26 if (encoding.name in escape_codes && escape_codes[encoding.name].ind
exOf(i) !== -1) | 26 if (encoding.name in escape_codes && escape_codes[encoding.name]
.indexOf(i) !== -1) |
27 continue; | 27 continue; |
28 string += String.fromCharCode(i); | 28 string += String.fromCharCode(i); |
29 bytes.push(i); | 29 bytes.push(i); |
30 } | 30 } |
31 | 31 |
32 decoder = null; | 32 var decoder = new TextDecoder(encoding.name); |
33 evalAndLog("decoder = new TextDecoder(" + JSON.stringify(encoding.name)
+ ")"); | 33 var decoded = decoder.decode(new Uint8Array(bytes)); |
34 if (decoder) { | 34 assert_equals(decoded, string); |
35 evalAndLog("decoded = decoder.decode(new Uint8Array(bytes))"); | 35 }, 'ASCII superset encoding: ' + encoding.name); |
36 // encodeURIComponent ensures output is printable | |
37 shouldBe("encodeURIComponent(string)", "encodeURIComponent(decoded)"
); | |
38 } | |
39 }); | 36 }); |
40 }); | 37 }); |
41 | 38 |
42 | |
43 </script> | 39 </script> |
OLD | NEW |