big5-enc-ascii.html (1941B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset=big5> <!-- test breaks if the server overrides this --> 5 <title>Big5 encoding ASCII</title> 6 <meta name="timeout" content="long"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <link rel='author' title='Richard Ishida' href='mailto:ishida@w3.org'> 10 <link rel='help' href='https://encoding.spec.whatwg.org/#big5'> 11 <meta name="assert" content="The browser produces the characters when encoding ASCII in a Big5-encoded document."> 12 </head> 13 <body> 14 <div id=log></div> 15 <script> 16 // index is Big5 index pointer, value is Unicode codepoint (dec) 17 18 function encode(input, output, desc) { 19 // tests whether a Unicode character is converted to an equivalent Big5 %-encoded byte sequence by href 20 // input: a escaped Unicode code point from the list of characters in the Big5 index 21 // output: expected percent-encoded byte sequence for the code point's equivalent in Big5 encoding 22 // desc: what's being tested 23 test(function() { 24 var a = document.createElement("a"); // <a> uses document encoding for URL's query 25 // Append and prepend x to test for off-by-one errors 26 a.href = "https://example.com/?x" + input + "x"; 27 assert_true( 28 a.search.substr(1) == "x" + output + "x" || 29 a.search.substr(1) == "x" + input + "x" 30 ); // remove leading "?" 31 }, "big5 encoder: " + desc); 32 } 33 34 // test ASCII - test separately for chars that aren't escaped 35 for (var a = 0; a < 0x7f; a++) { 36 // The first 3 are stripped from URLs and the last is # which introduces a new URL segment 37 if (a === 0x09 || a === 0x0a || a === 0x0d || a === 0x23) { 38 continue; 39 } 40 hex = a.toString(16).toUpperCase(); 41 while (hex.length < 2) { 42 hex = "0" + hex; 43 } 44 encode( 45 String.fromCharCode(a), 46 "%" + hex, 47 "test for ASCII codepoint 0x" + 48 a.toString(16) + 49 " " + 50 String.fromCharCode(a) 51 ); 52 } 53 </script> 54 </body> 55 </html>