Home | History | Annotate | Download | only in xpath
      1 <html>
      2 <head>
      3 <link rel="stylesheet" href="../js/resources/js-test-style.css">
      4 <script src="../js/resources/js-test-pre.js"></script>
      5 <script src="xpath-test-pre.js"></script>
      6 <style>
      7 #context {display:none}
      8 </style>
      9 </head>
     10 <body>
     11 <p>Test that an NCName and * are interpreted as an operator when in
     12 binary operator context, and as a NameTest otherwise.
     13 
     14 <p>See <a href="http://bugs.webkit.org/show_bug.cgi?id=50366">bug 50366</a>:
     15 XPath lexer misinterprets expression starting with "div".</p>
     16 
     17 <div id="console"></div>
     18 
     19 <div id="context">
     20   <div id="two" div="x">2</div>
     21 </div>
     22 
     23 <script>
     24 var context = document.getElementById('context');
     25 var div = document.getElementById('two');
     26 
     27 // =========== div ===========
     28 
     29 test(document, context, "div", [div], null);  // div with no preceding token
     30 test(document, context, "  div", [div], null);
     31 // div following every possible [28] ExprToken http://www.w3.org/TR/xpath/
     32 test(document, context, "(div) div (div)", 2/2, null);  // div after ( and )
     33 test(document, context, "self::node()[div] div 1", 2/1, null);  // div after [ and ]
     34 test(document, context, ". div .", 2/2, null);  // div after .
     35 test(document, div, ".. div ..", 2/2, null);  // div after ..
     36 test(document, context, "string(div/@div)", "x", null);  // div after @
     37 test(document, context, "substring-before('1992', div)", "199", null);  // div after ,
     38 test(document, div, "self::div", [div], null);  // div after ::
     39 test(document, context, "* div 4", 2/4, null);  // div after NameTest *
     40 test(document, context, "'3' div 4", 3/4, null);  // div after Literal
     41 test(document, context, "\"3\" div 4", 3/4, null);  // div after Literal
     42 test(document, context, "12 div 4", 12/4, null);  // div after Number
     43 
     44 // div following every [32] Operator
     45 test(document, context, "true() and div", true, null);  // div after OperatorName and
     46 test(document, context, "false() or div", true, null);  // div after OperatorName or
     47 test(document, context, "div mod div", 0, null);  // div after OperatorName mod
     48 test(document, context, "div div div", 1, null);  // div after OperatorName div
     49 test(document, context, "3 * div", 6, null);  // div after MultiplyOperator
     50 test(document, context, "div/div", [], null);  // div after /
     51 test(document, context, "div//div", [], null);  // div after //
     52 test(document, context, "zz|div", [div], null);  // div after |
     53 test(document, context, "div+div", 4, null);  // div after +
     54 test(document, context, "- - div", 2, null);  // div after unary -
     55 test(document, context, "5 -div", 3, null);  // div after binary -
     56 test(document, context, "div=div", true, null);  // div after =
     57 test(document, context, "div!=div", false, null);  // div after =
     58 test(document, context, "div<div", false, null);  // div after <
     59 test(document, context, "div<=div", true, null);  // div after <=
     60 test(document, context, "div>div", false, null);  // div after >
     61 test(document, context, "div>=div", true, null);  // div after >=
     62 
     63 
     64 // =========== * ===========
     65 
     66 test(document, context, "*", [div], null);  // * with no preceding token
     67 test(document, context, "  *", [div], null);
     68 // * following every possible [28] ExprToken http://www.w3.org/TR/xpath/
     69 test(document, context, "(*) * (*)", 2*2, null);  // * after ( and )
     70 test(document, context, "self::node()[*] * 1", 2*1, null);  // * after [ and ]
     71 test(document, context, ". * .", 2*2, null);  // * after .
     72 test(document, div, ".. * ..", 2*2, null);  // * after ..
     73 // (* can't follow @)
     74 test(document, context, "substring-before('1992', *)", "199", null);  // * after ,
     75 test(document, div, "self::*", [div], null);  // * after ::
     76 test(document, context, "* * 4", 2*4, null);  // * after NameTest *
     77 test(document, context, "'3' * 4", 3*4, null);  // * after Literal
     78 test(document, context, "\"3\" * 4", 3*4, null);  // * after Literal
     79 test(document, context, "12 * 4", 12*4, null);  // * after Number
     80 
     81 // * following every [32] Operator
     82 test(document, context, "true() and *", true, null);  // * after OperatorName and
     83 test(document, context, "false() or *", true, null);  // * after OperatorName or
     84 test(document, context, "* mod *", 0, null);  // * after OperatorName mod
     85 test(document, context, "* div *", 1, null);  // * after OperatorName div
     86 test(document, context, "3 * *", 6, null);  // * after MultiplyOperator
     87 test(document, context, "*/*", [], null);  // * after /
     88 test(document, context, "*//*", [], null);  // * after //
     89 test(document, context, "zz|*", [div], null);  // * after |
     90 test(document, context, "*+*", 4, null);  // * after +
     91 test(document, context, "- - *", 2, null);  // * after unary -
     92 test(document, context, "5 -*", 3, null);  // * after binary -
     93 test(document, context, "*=*", true, null);  // * after =
     94 test(document, context, "*!=*", false, null);  // * after =
     95 test(document, context, "*<*", false, null);  // * after <
     96 test(document, context, "*<=*", true, null);  // * after <=
     97 test(document, context, "*>*", false, null);  // * after >
     98 test(document, context, "*>=*", true, null);  // * after >=
     99 
    100 var xmlDoc = (new DOMParser).parseFromString("<or xmlns='uri'>5</or>", "text/xml");
    101 var nsResolver = function(prefix) {return 'uri';}
    102 // div and * after :
    103 test(xmlDoc, xmlDoc, "or:or", [xmlDoc.documentElement], nsResolver);
    104 test(xmlDoc, xmlDoc, "or:*", [xmlDoc.documentElement], nsResolver);
    105 
    106 // A few tests with mod as well
    107 var xmlDoc2 = (new DOMParser).parseFromString("<mod and='x'>8</mod>", "text/xml");
    108 test(xmlDoc2, xmlDoc2, "mod", [xmlDoc2.documentElement], null);
    109 test(xmlDoc2, xmlDoc2, "mod mod mod", 0, null);
    110 test(xmlDoc2, xmlDoc2, "(mod) mod 5", 3, null);
    111 test(xmlDoc2, xmlDoc2, "string(mod/@and)", 'x', null);
    112 
    113 
    114 var successfullyParsed = true;
    115 </script>
    116 <script src="../js/resources/js-test-post.js"></script>
    117 </body>
    118 </html>
    119