blob: a88c82f13178ab31be3df786f801547d51161a75 [file] [log] [blame]
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
<script src="../xpath-test-pre.js"></script>
</head>
<body>
<div id="console"></div>
<script>
var doc = (new DOMParser).parseFromString(
'<doc>' +
'<item id="1" />' +
'<item id="2" />' +
'<item id="3" />' +
'<item id="4" />' +
'<item id="5" />' +
'</doc>',
'application/xml');
var ROOT = doc.documentElement;
var ITEM1 = ROOT.firstChild;
var ITEM2 = ITEM1.nextSibling;
var ITEM3 = ITEM2.nextSibling;
var ITEM4 = ITEM3.nextSibling;
test(doc, doc.documentElement, '//item[@id >= 2 and @id <= "4"]', [ITEM2, ITEM3, ITEM4]);
test(doc, doc.documentElement, '//item[@id >= 2 and @id <= 3]', [ITEM2, ITEM3]);
shouldThrow('doc.evaluate("position(1)", doc.documentElement, null, XPathResult.ANY_TYPE, null)');
shouldThrow('doc.evaluate("not()", doc.documentElement, null, XPathResult.ANY_TYPE, null)');
test(doc, doc, "string-length(100)", 3);
shouldThrow('doc.evaluate("count(100)", doc.documentElement, null, XPathResult.ANY_TYPE, null)');
shouldThrow('doc.evaluate("adumbrate()", doc.documentElement, null, XPathResult.ANY_TYPE, null)');
var doc = (new DOMParser).parseFromString(
'<doc>' +
'<item id="1" />' +
'<item id="2" />' +
'<item id="3" />' +
'<item id="4" />' +
'<item id="5" />' +
'<item id="6" />' +
'<item id="7" />' +
'<item id="8" />' +
'<item id="9" />' +
'</doc>',
'application/xml');
var ROOT = doc.documentElement;
var ITEM1 = ROOT.firstChild;
var ITEM2 = ITEM1.nextSibling;
var ITEM3 = ITEM2.nextSibling;
var ITEM4 = ITEM3.nextSibling;
var ITEM5 = ITEM4.nextSibling;
var ITEM6 = ITEM5.nextSibling;
var ITEM7 = ITEM6.nextSibling;
var ITEM8 = ITEM7.nextSibling;
var ITEM9 = ITEM8.nextSibling;
test(doc, doc.documentElement, '//item[@id mod 2 = 0] | //item[@id mod 3 = 0]', [ITEM2, ITEM3, ITEM4, ITEM6, ITEM8, ITEM9]);
shouldThrow('doc.evaluate("//item | 42", doc.documentElement, null, XPathResult.ANY_TYPE, null)');
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.
shouldThrow("doc.evaluate('\"monty\"/anaconda', doc.documentElement, null, XPathResult.ANY_TYPE, null)");
shouldThrow("doc.evaluate('/doc/string(item[@id = 2])/@id', doc.documentElement, null, XPathResult.ANY_TYPE, null)");
shouldThrow("doc.evaluate('(1)[1]', doc.documentElement, null, XPathResult.ANY_TYPE, null)");
// Added for WebKit.
test(doc, doc.documentElement, '(1)', 1);
test(doc, doc.documentElement, '((1 + 1))', 2);
var doc = (new DOMParser).parseFromString(
'<doc>' +
' <set id="1">' +
' <item>1</item>' +
' <item>2</item>' +
' <item>3</item>' +
' <item>4</item>' +
' </set>' +
' <set id="2">' +
' <item>5</item>' +
' <item>6</item>' +
' <item>7</item>' +
' <item>8</item>' +
' </set>' +
' <set id="3">' +
' <item>0</item>' +
' <item>3</item>' +
' <item>6</item>' +
' <item>9</item>' +
' </set>' +
' <set id="4">' +
' <item>42.0</item>' +
' </set>' +
'</doc>',
'application/xml');
test(doc, doc.documentElement, '1 or 1', true);
test(doc, doc.documentElement, '1 or 0', true);
test(doc, doc.documentElement, '0 or 1', true);
test(doc, doc.documentElement, '0 or 0', false);
test(doc, doc.documentElement, '1 and 1', true);
test(doc, doc.documentElement, '1 and 0', false);
test(doc, doc.documentElement, '0 and 1', false);
test(doc, doc.documentElement, '0 and 0', false);
test(doc, doc.documentElement, '(//set[@id=1]/*) = (//set[@id=3]/*)', true);
test(doc, doc.documentElement, '(//set[@id=1]/*) = (//set[@id=2]/*)', false);
test(doc, doc.documentElement, '(//set[@id=1]/*) != (//set[@id=1]/*)', true);
test(doc, doc.documentElement, '(//set[@id=4]/*) != (//set[@id=4]/*)', false);
test(doc, doc.documentElement, '(//set[@id=1]/*) <= (//set[@id=2]/*)', true);
test(doc, doc.documentElement, '(//set[@id=2]/*) <= (//set[@id=1]/*)', false);
test(doc, doc.documentElement, '(//set[@id=1]/*) < (//set[@id=2]/*)', true);
test(doc, doc.documentElement, '(//set[@id=2]/*) < (//set[@id=1]/*)', false);
test(doc, doc.documentElement, '(//set[@id=2]/*) > (//set[@id=1]/*)', true);
test(doc, doc.documentElement, '(//set[@id=1]/*) > (//set[@id=2]/*)', false);
test(doc, doc.documentElement, '(//set[@id=2]/*) >= (//set[@id=1]/*)', true);
test(doc, doc.documentElement, '(//set[@id=1]/*) >= (//set[@id=2]/*)', false);
test(doc, doc.documentElement, '(//set[@id=4]/*) = (1 = 1)', true);
test(doc, doc.documentElement, '(//set[@id=4]/*) = (1 = 0)', false);
test(doc, doc.documentElement, '(//set[@id=4]/*) != (1 = 0)', true);
test(doc, doc.documentElement, '(//set[@id=4]/*) != (1 = 1)', false);
test(doc, doc.documentElement, '(//set[@id=4]/*) = 42', true);
test(doc, doc.documentElement, '(//set[@id=4]/*) = 43', false);
test(doc, doc.documentElement, '(//set[@id=4]/*) != 43', true);
test(doc, doc.documentElement, '(//set[@id=4]/*) != 42', false);
test(doc, doc.documentElement, '(//set[@id=4]/*) = "42.0"', true);
test(doc, doc.documentElement, '(//set[@id=4]/*) = "42"', false);
test(doc, doc.documentElement, '(//set[@id=4]/*) != "42"', true);
test(doc, doc.documentElement, '(//set[@id=4]/*) != "42.0"', false);
test(doc, doc.documentElement, '"a" <= "a"', false);
test(doc, doc.documentElement, '"a" <= "b"', false);
test(doc, doc.documentElement, '"a" >= "a"', false);
test(doc, doc.documentElement, '"b" > "a"', false);
test(doc, doc.documentElement, '1 <= 1', true);
test(doc, doc.documentElement, '2 <= 1', false);
test(doc, doc.documentElement, '1 < 2', true);
test(doc, doc.documentElement, '1 < 1', false);
test(doc, doc.documentElement, '1 >= 1', true);
test(doc, doc.documentElement, '1 >= 2', false);
test(doc, doc.documentElement, '2 > 1', true);
test(doc, doc.documentElement, '1 > 1', false);
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>