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 </head> 7 <body> 8 <div id="console"></div> 9 10 <script> 11 var doc = (new DOMParser).parseFromString( 12 '<doc>' + 13 '<item id="1" />' + 14 '<item id="2" />' + 15 '<item id="3" />' + 16 '<item id="4" />' + 17 '<item id="5" />' + 18 '</doc>', 19 'application/xml'); 20 21 var ROOT = doc.documentElement; 22 var ITEM1 = ROOT.firstChild; 23 var ITEM2 = ITEM1.nextSibling; 24 var ITEM3 = ITEM2.nextSibling; 25 var ITEM4 = ITEM3.nextSibling; 26 27 test(doc, doc.documentElement, '//item[@id >= 2 and @id <= "4"]', [ITEM2, ITEM3, ITEM4]); 28 test(doc, doc.documentElement, '//item[@id >= 2 and @id <= 3]', [ITEM2, ITEM3]); 29 shouldThrow('doc.evaluate("position(1)", doc.documentElement, null, XPathResult.ANY_TYPE, null)'); 30 shouldThrow('doc.evaluate("not()", doc.documentElement, null, XPathResult.ANY_TYPE, null)'); 31 test(doc, doc, "string-length(100)", 3); 32 shouldThrow('doc.evaluate("count(100)", doc.documentElement, null, XPathResult.ANY_TYPE, null)'); 33 shouldThrow('doc.evaluate("adumbrate()", doc.documentElement, null, XPathResult.ANY_TYPE, null)'); 34 35 var doc = (new DOMParser).parseFromString( 36 '<doc>' + 37 '<item id="1" />' + 38 '<item id="2" />' + 39 '<item id="3" />' + 40 '<item id="4" />' + 41 '<item id="5" />' + 42 '<item id="6" />' + 43 '<item id="7" />' + 44 '<item id="8" />' + 45 '<item id="9" />' + 46 '</doc>', 47 'application/xml'); 48 49 var ROOT = doc.documentElement; 50 var ITEM1 = ROOT.firstChild; 51 var ITEM2 = ITEM1.nextSibling; 52 var ITEM3 = ITEM2.nextSibling; 53 var ITEM4 = ITEM3.nextSibling; 54 var ITEM5 = ITEM4.nextSibling; 55 var ITEM6 = ITEM5.nextSibling; 56 var ITEM7 = ITEM6.nextSibling; 57 var ITEM8 = ITEM7.nextSibling; 58 var ITEM9 = ITEM8.nextSibling; 59 60 test(doc, doc.documentElement, '//item[@id mod 2 = 0] | //item[@id mod 3 = 0]', [ITEM2, ITEM3, ITEM4, ITEM6, ITEM8, ITEM9]); 61 shouldThrow('doc.evaluate("//item | 42", doc.documentElement, null, XPathResult.ANY_TYPE, null)'); 62 shouldThrow('doc.evaluate("/doc/(item[@id = 2] | item[@id = 6])/@id", doc.documentElement, null, XPathResult.ANY_TYPE, null)'); // This test doesn't throw in py-dom-path, which is a bug. 63 shouldThrow("doc.evaluate('\"monty\"/anaconda', doc.documentElement, null, XPathResult.ANY_TYPE, null)"); 64 shouldThrow("doc.evaluate('/doc/string(item[@id = 2])/@id', doc.documentElement, null, XPathResult.ANY_TYPE, null)"); 65 shouldThrow("doc.evaluate('(1)[1]', doc.documentElement, null, XPathResult.ANY_TYPE, null)"); 66 67 // Added for WebKit. 68 test(doc, doc.documentElement, '(1)', 1); 69 test(doc, doc.documentElement, '((1 + 1))', 2); 70 71 var doc = (new DOMParser).parseFromString( 72 '<doc>' + 73 ' <set id="1">' + 74 ' <item>1</item>' + 75 ' <item>2</item>' + 76 ' <item>3</item>' + 77 ' <item>4</item>' + 78 ' </set>' + 79 ' <set id="2">' + 80 ' <item>5</item>' + 81 ' <item>6</item>' + 82 ' <item>7</item>' + 83 ' <item>8</item>' + 84 ' </set>' + 85 ' <set id="3">' + 86 ' <item>0</item>' + 87 ' <item>3</item>' + 88 ' <item>6</item>' + 89 ' <item>9</item>' + 90 ' </set>' + 91 ' <set id="4">' + 92 ' <item>42.0</item>' + 93 ' </set>' + 94 '</doc>', 95 'application/xml'); 96 97 test(doc, doc.documentElement, '1 or 1', true); 98 test(doc, doc.documentElement, '1 or 0', true); 99 test(doc, doc.documentElement, '0 or 1', true); 100 test(doc, doc.documentElement, '0 or 0', false); 101 test(doc, doc.documentElement, '1 and 1', true); 102 test(doc, doc.documentElement, '1 and 0', false); 103 test(doc, doc.documentElement, '0 and 1', false); 104 test(doc, doc.documentElement, '0 and 0', false); 105 test(doc, doc.documentElement, '(//set[@id=1]/*) = (//set[@id=3]/*)', true); 106 test(doc, doc.documentElement, '(//set[@id=1]/*) = (//set[@id=2]/*)', false); 107 test(doc, doc.documentElement, '(//set[@id=1]/*) != (//set[@id=1]/*)', true); 108 test(doc, doc.documentElement, '(//set[@id=4]/*) != (//set[@id=4]/*)', false); 109 test(doc, doc.documentElement, '(//set[@id=1]/*) <= (//set[@id=2]/*)', true); 110 test(doc, doc.documentElement, '(//set[@id=2]/*) <= (//set[@id=1]/*)', false); 111 test(doc, doc.documentElement, '(//set[@id=1]/*) < (//set[@id=2]/*)', true); 112 test(doc, doc.documentElement, '(//set[@id=2]/*) < (//set[@id=1]/*)', false); 113 test(doc, doc.documentElement, '(//set[@id=2]/*) > (//set[@id=1]/*)', true); 114 test(doc, doc.documentElement, '(//set[@id=1]/*) > (//set[@id=2]/*)', false); 115 test(doc, doc.documentElement, '(//set[@id=2]/*) >= (//set[@id=1]/*)', true); 116 test(doc, doc.documentElement, '(//set[@id=1]/*) >= (//set[@id=2]/*)', false); 117 test(doc, doc.documentElement, '(//set[@id=4]/*) = (1 = 1)', true); 118 test(doc, doc.documentElement, '(//set[@id=4]/*) = (1 = 0)', false); 119 test(doc, doc.documentElement, '(//set[@id=4]/*) != (1 = 0)', true); 120 test(doc, doc.documentElement, '(//set[@id=4]/*) != (1 = 1)', false); 121 test(doc, doc.documentElement, '(//set[@id=4]/*) = 42', true); 122 test(doc, doc.documentElement, '(//set[@id=4]/*) = 43', false); 123 test(doc, doc.documentElement, '(//set[@id=4]/*) != 43', true); 124 test(doc, doc.documentElement, '(//set[@id=4]/*) != 42', false); 125 test(doc, doc.documentElement, '(//set[@id=4]/*) = "42.0"', true); 126 test(doc, doc.documentElement, '(//set[@id=4]/*) = "42"', false); 127 test(doc, doc.documentElement, '(//set[@id=4]/*) != "42"', true); 128 test(doc, doc.documentElement, '(//set[@id=4]/*) != "42.0"', false); 129 test(doc, doc.documentElement, '"a" <= "a"', false); 130 test(doc, doc.documentElement, '"a" <= "b"', false); 131 test(doc, doc.documentElement, '"a" >= "a"', false); 132 test(doc, doc.documentElement, '"b" > "a"', false); 133 test(doc, doc.documentElement, '1 <= 1', true); 134 test(doc, doc.documentElement, '2 <= 1', false); 135 test(doc, doc.documentElement, '1 < 2', true); 136 test(doc, doc.documentElement, '1 < 1', false); 137 test(doc, doc.documentElement, '1 >= 1', true); 138 test(doc, doc.documentElement, '1 >= 2', false); 139 test(doc, doc.documentElement, '2 > 1', true); 140 test(doc, doc.documentElement, '1 > 1', false); 141 142 143 var successfullyParsed = true; 144 145 </script> 146 <script src="../../js/resources/js-test-post.js"></script> 147 </body> 148 </html> 149