tor-browser

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

anb-serialization.html (1397B)


      1 <!doctype html>
      2 <title>An+B Serialization</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <style>
      6 
      7 foo { color: blue; }
      8 
      9 </style>
     10 
     11 <meta name="author" title="Tab Atkins-Bittner">
     12 <link rel=help href="https://drafts.csswg.org/css-syntax/#serializing-anb">
     13 
     14 <script>
     15 
     16 function roundtripANB(str) {
     17    const rule = document.styleSheets[0].cssRules[0];
     18    rule.selectorText = "foo";
     19    rule.selectorText = `:nth-child(${str})`;
     20    // Check for parse error.
     21    if(rule.selectorText == "foo") return "parse error";
     22    return rule.selectorText.slice(11, -1);
     23 }
     24 function testANB(input, expected) {
     25    test(()=>{
     26        assert_equals(roundtripANB(input), expected);
     27    }, `"${input}" becomes "${expected}"`);
     28 }
     29 
     30 /* A is 0, or omitted */
     31 testANB("1", "1");
     32 testANB("+1", "1");
     33 testANB("-1", "-1");
     34 testANB("0n + 0", "0");
     35 testANB("0n + 1", "1");
     36 testANB("0n - 1", "-1");
     37 
     38 /* A is 1 */
     39 testANB("1n", "n");
     40 testANB("1n - 0", "n");
     41 testANB("1n + 1", "n+1");
     42 testANB("1n - 1", "n-1");
     43 
     44 /* A is -1 */
     45 testANB("-1n", "-n");
     46 testANB("-1n - 0", "-n");
     47 testANB("-1n + 1", "-n+1");
     48 testANB("-1n - 1", "-n-1");
     49 
     50 /* A is implied via + or - */
     51 testANB("+n+1", "n+1");
     52 testANB("-n-1", "-n-1");
     53 
     54 /* B is 0 */
     55 testANB("n + 0", "n");
     56 testANB("n - 0", "n");
     57 
     58 /* A & B both nonzero */
     59 testANB("2n + 2", "2n+2");
     60 testANB("-2n - 2", "-2n-2");
     61 
     62 </script>