<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css">
<script src="../js/resources/js-test-pre.js"></script>
<script src="xpath-test-pre.js"></script>
</head>
<body>
<div id="console"></div>
<script>
var ROOT = document.createElement('div');
ROOT.innerHTML = '<p>a</p><div><span id="21"></span><span id="22"></span><span id="23"></span></div>';
var CHILD1 = ROOT.firstChild;
var CHILD1TEXT = CHILD1.firstChild;
var CHILD2 = ROOT.lastChild;
var CHILD21 = CHILD2.firstChild;
var CHILD22 = CHILD21.nextSibling;
var CHILD23 = CHILD22.nextSibling;
result = document.evaluate(".//*", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot(".//*", result, [CHILD1, CHILD2, CHILD21, CHILD22, CHILD23]);
result = document.evaluate("*[position() = 2]", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot("*[position() = 2]", result, [CHILD2]);
result = document.evaluate(".//*[position() = 2]", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot(".//*[position() = 2]", result, [CHILD2, CHILD22]);
result = document.evaluate("./././/*[2]/.", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot("./././/*[2]/.", result, [CHILD2, CHILD22]);
result = document.evaluate(".//*/span[2]", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot(".//*/span[2]", result, [CHILD22]);
result = document.evaluate(".//*[position() = 1]", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot(".//*[position() = 1]", result, [CHILD1, CHILD21]);
result = document.evaluate("./descendant-or-self::node()/child::*[position() = 2]", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot("./descendant-or-self::node()/child::*[position() = 2]", result, [CHILD2, CHILD22]);
result = document.evaluate("descendant-or-self::node()/child::*[position() = 2]", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot("descendant-or-self::node()/child::*[position() = 2]", result, [CHILD2, CHILD22]);
result = document.evaluate(".//*/*[2]", ROOT, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot(".//*/*[2]", result, [CHILD22]);
result = document.evaluate("preceding::node()[1]", CHILD2, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot("preceding::node()[1]", result, [CHILD1TEXT]);
result = document.evaluate("preceding::node()[2]", CHILD2, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot("preceding::node()[2]", result, [CHILD1]);
result = document.evaluate("preceding::node()[3]", CHILD2, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot("preceding::node()[3]", result, []);
result = document.evaluate("preceding::node()/*[3]", CHILD2, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot("preceding::node()/*[3]", result, []);
result = document.evaluate("ancestor::node()[2]", CHILD21, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot("ancestor::node()[2]", result, [ROOT]);
result = document.evaluate("ancestor-or-self::node()[2]", CHILD21, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot("ancestor-or-self::node()[2]", result, [CHILD2]);
result = document.evaluate("ancestor-or-self::node()[3]", CHILD21, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot("ancestor-or-self::node()[3]", result, [ROOT]);
result = document.evaluate("preceding::span[1]", CHILD23, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot("preceding::span[1]", result, [CHILD22]);
result = document.evaluate("(preceding::span)[1]", CHILD23, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot("(preceding::span)[1]", result, [CHILD21]);
var ROOT2 = document.createElement('div');
ROOT2.innerHTML = '<p num="1"></p><p num="2" type="warning"></p><p num="3" type="warning"></p><p num="4" type="warning"></p><p num="5" type="warning"></p><p num="6" type="warning"></p>';
shouldBe("document.evaluate('p[@type=\"warning\"][5]/@num', ROOT2, null, XPathResult.STRING_TYPE, null).stringValue", "'6'");
shouldBe("document.evaluate('p[5][@type=\"warning\"]/@num', ROOT2, null, XPathResult.STRING_TYPE, null).stringValue", "'5'");
var successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>