tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

non-ascii-codepoints.html (2179B)


      1 <!doctype html>
      2 <title>Non-ASCII codepoints</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 
      6 <meta name="author" title="Tab Atkins-Bittner">
      7 <link rel=help href="https://drafts.csswg.org/css-syntax/#non-ascii-ident-code-point">
      8 
      9 <script>
     10 function validIdentChar(cp) {
     11  // Reset to a known-good ident
     12  document.head.style.animationName = "foo";
     13  // Then change to a name containing the char
     14    document.head.style.animationName = "f"+String.fromCodePoint(cp)+"oo";
     15    // And see if it actually changed.
     16    return document.head.style.animationName != "foo";
     17 }
     18 
     19 function testValid(cp) {
     20  test(()=>{
     21    assert_true(validIdentChar(cp));
     22  }, `Codepoint U+${cp.toString(16)} is a valid 'non-ASCII ident codepoint'.`)
     23 }
     24 
     25 function testInvalid(cp) {
     26  // Just skip if the codepoint is outside the possible range.
     27  if(cp > 0x1ffff) return;
     28  test(()=>{
     29    assert_false(validIdentChar(cp));
     30  }, `Codepoint U+${cp.toString(16)} is not a 'non-ASCII ident codepoint'.`)
     31 }
     32 
     33 function testValidRanges(ranges) {
     34  // Takes an array of codepoints or codepoints ranges,
     35  // and tests whether the start, end, and middle of
     36  // each range is valid, and confirms that the
     37  // start/end of the regions between them are invalid.
     38 
     39  for(const range of ranges) {
     40    if(typeof range == "number") {
     41      testValid(range);
     42      continue;
     43    }
     44    testValid(range[0]);
     45    if(range[1] - range[0] > 1) {
     46      testValid(Math.floor((range[0]+range[1])/2));
     47    }
     48    testValid(range[1]);
     49  }
     50  testInvalid(0x80);
     51  var lastTested = 0x80;
     52  for(const range of ranges) {
     53    if(typeof range == "number") {
     54      if(range-1 != lastTested) testInvalid(range-1);
     55      testInvalid(range+1);
     56      lastTested = range+1;
     57      continue;
     58    }
     59    if(range[0]-1 != lastTested) testInvalid(range[0]-1);
     60    testInvalid(range[1]+1);
     61    lastTested = range[1]+1;
     62  }
     63 
     64 }
     65 
     66 testValidRanges([
     67  0xb7,
     68  [0xc0, 0xd6],
     69  [0xd8, 0xf6],
     70  [0xf8, 0x37d],
     71  [0x37f, 0x1fff],
     72  [0x200c, 0x200d],
     73  [0x203f, 0x2040]
     74  [0x2070, 0x218f],
     75  [0x2c00, 0x2fef],
     76  [0x3001, 0xd7ff],
     77  [0xf900, 0xfdcf],
     78  [0xfdf0, 0xfffd],
     79  [0x10000, 0x1ffff],
     80 ]);
     81 </script>