blob: e6219538327f5c96139ae01f5c18472ff7e93f8b [file] [log] [blame]
<html>
<head>
<title>XPath Test</title>
<script>
if (window.testRunner)
testRunner.dumpAsText();
function test(expression, expect) {
function error(message) {
var e = Error();
e.result = result;
e.expects = expects;
e.expression = expression;
e.message = message;
return e
};
var result = document.evaluate(expression, document.body, null, 7, null);
var expects = expect.split(/\s+/);
for (var i = 0, l = expects.length; i < l; i++) if (expects[i] == '') expects.splice(i, 1);
if (result.snapshotLength != expects.length) throw error();
for (var i = 0, l = expects.length; i < l; i++) {
var expect = expects[i];
var r = expect.match(/^(?:([atpc]):)?(.*)$/);
var node = result.snapshotItem(i);
if (!types[r[1] || ''](node, r[2])) throw error();
}
return true;
};
window.onload = function() {
var ul = document.createElement('ul');
for (var i = 0, l = data.length; i < l; i ++) {
var li = document.createElement('li');
try {
test.apply(null, data[i]);
li.appendChild(document.createTextNode('[ok]' + data[i][0]));
li.className = 'ok';
li.style.color = 'green';
}
catch (e) {
li.appendChild(document.createTextNode('[ng]' + data[i][0]));
li.className = 'ng';
li.style.color = 'red';
}
ul.appendChild(li);
}
document.body.insertBefore(ul, document.body.firstChild);
};
var types = {
a: function(node, expect) {
var r = expect.split(':');
return r[0] == node.nodeName && r[1] == node.nodeValue;
},
t: function(node, expect) {
return expect == node.nodeValue;
},
p: function(node, expect) {
return expect == node.nodeName;
},
c: function(node, expect) {
return expect == node.nodeValue;
},
'': function(node, expect) {
return expect.toLowerCase() == node.nodeName.toLowerCase();
}
};
var data = [
['.//blockquote/*', 'br p font'],
['.//blockquote/child::*', 'br p font'],
['.//blockquote/parent::*', 'center'],
['.//blockquote/descendant::*', 'br p del ins font'],
['.//blockquote/descendant-or-self::*', 'blockquote br p del ins font'],
['.//blockquote/ancestor::*', 'html body div center'],
['.//blockquote/ancestor-or-self::*', 'html body div center blockquote'],
['.//blockquote/following-sibling::*', 'h3 h4'],
['.//blockquote/preceding-sibling::*', 'h1 h2'],
['.//blockquote/following::*', 'h3 dfn a h4 sub sup span abbr q'],
['.//blockquote/preceding::*', 'head title script dl dt dd h1 em strong h2 b s'],
['.//blockquote/self::*', 'blockquote'],
['.//blockquote/attribute::id/parent::*', 'blockquote'],
['.//blockquote/@id/parent::*', 'blockquote'],
['.//*[blockquote]', 'center'],
['.//*[child::blockquote]', 'center'],
['.//*[parent::blockquote]', 'br p font'],
['.//*[descendant::blockquote]', 'div center'],
['.//*[descendant-or-self::blockquote]', 'div center blockquote'],
['.//*[ancestor::blockquote]', 'br p del ins font'],
['.//*[ancestor-or-self::blockquote]', 'blockquote br p del ins font'],
['.//*[following-sibling::blockquote]', 'h1 h2'],
['.//*[preceding-sibling::blockquote]', 'h3 h4'],
['.//*[following::blockquote]', 'dl dt dd h1 em strong h2 b s'],
['.//*[preceding::blockquote]', 'h3 dfn a h4 sub sup span abbr q'],
['.//*[self::blockquote]', 'blockquote'],
['.//*[@id]', 'div dl dt dd center h1 em strong h2 b s blockquote br p del ins font h3 dfn a h4 sub sup span abbr q'],
['.//*[attribute::id]', 'div dl dt dd center h1 em strong h2 b s blockquote br p del ins font h3 dfn a h4 sub sup span abbr q'],
['.//blockquote/text()', 't:blockquoteText1: t:blockquoteText2'],
['.//blockquote/comment()', 'c:blockquoteComment'],
['.//blockquote/processing-instruction()', 'p:pi'],
['.//blockquote/processing-instruction("pi")', 'p:pi'],
['.//blockquote/node()', 'c:blockquoteComment t:blockquoteText1: br t:blockquoteText2 p p:pi font'],
['.//blockquote/p', 'p'],
['.//blockquote/*', 'br p font'],
['.//*[child::* and preceding::font]', 'h3 h4 span'],
['.//*[not(child::*) and preceding::font]', 'dfn a sub sup abbr q'],
['.//*[preceding::blockquote or following::blockquote]',
'dl dt dd h1 em strong h2 b s h3 dfn a h4 sub sup span abbr q'],
['.//blockquote/ancestor::* | .//blockquote/descendant::*', 'html body div center br p del ins font'],
['.//*[.="sub"]', 'sub'],
['.//*[@title > 12 and @class < 15]', 'br p del ins font'],
['.//*[@title != @class]',
'div dl dt dd center em strong b s blockquote br p del ins font dfn a sub sup span abbr q'],
['.//*[((@class * @class + @title * @title) div (@class + @title)) > ((@class - @title) * (@class - @title))]',
'dl h1 h2 s blockquote br p font h3 dfn a h4 sub sup span abbr q'],
['.//*[@title mod 2 = 0]', 'dl dd h1 strong b blockquote p ins h3 a sub span q'],
['.//blockquote/child::*[last()]', 'font'],
['.//blockquote/descendant::*[position() < 4]', 'br p del'],
['id(.//font/@face)', 'strong q'],
['.//*[name(.) = "sub"]', 'sub'],
['.//*[name() = "sub"]', 'sub'],
['.//blockquote/child::*[2]', 'p'],
['.//blockquote/descendant::*[4]', 'ins'],
['.//blockquote/descendant-or-self::*[4]', 'del'],
['.//blockquote/ancestor::*[2]', 'div'],
['.//blockquote/ancestor-or-self::*[2]', 'center'],
['.//blockquote/following-sibling::*[1]', 'h3'],
['.//blockquote/preceding-sibling::*[1]', 'h2'],
['.//blockquote/following::*[4]', 'h4'],
['.//blockquote/preceding::*[4]', 'strong'],
['.//*[starts-with(.,"s")]', 'strong s h4 sub sup'],
['.//*[string(@title - 1) = "0"]', 'div'],
['.//*[string() = "sub"]', 'sub'],
['.//*[string(.) = "sub"]', 'sub'],
['.//*[concat(.,..) = "subsubsup"]', 'sub'],
['.//node()[concat(.,..,../..) = "bbbs"]', 't:b'],
['.//*[starts-with(.,"s")]', 'strong s h4 sub sup'],
['.//*[substring-before(.,"u") = "s"]', 'h4 sub sup'],
['.//*[substring-after(.,"on") = "t"]', 'blockquote font'],
['.//*[substring(.,2,1) = "u"]', 'h4 sub sup'],
['.//*[substring(.,2) = "up"]', 'sup'],
['.//*[contains(.,"b")]', 'div center h2 b blockquote h4 sub span abbr'],
['.//*[string-length() = 3]', 'del ins dfn sub sup'],
['.//*[string-length(.) = 3]', 'del ins dfn sub sup'],
['.//*[.=translate(normalize-space(" s u b ")," ","")]', 'sub'],
['.//*[normalize-space()="q"]', 'q'],
['.//*[boolean(@title - 1) = false()]', 'div'],
['.//*[not(@title - 1) = true()]', 'div'],
['.//*[lang("it")]', 'q'],
['.//*[number(@title) < number(@class)]', 'div dl center blockquote span'],
['.//*[sum(ancestor::*/@title) < sum(descendant::*/@title)]',
'div dl center h1 h2 blockquote p h3 h4 span'],
['.//*[floor(@title div @class) = 1]',
'h1 em strong h2 b s br p del ins font h3 dfn a h4 sub sup abbr q'],
['.//*[ceiling(@title div @class) = 1]', 'div dl center h1 h2 blockquote h3 h4 span'],
['.//*[round(@title div @class) = 1]',
'dl h1 h2 b s blockquote br p del ins font h3 dfn a h4 sub sup span abbr q'],
['.//*[blockquote]', 'center']
];
</script>
</head>
<body><div id="n1" title="1" class="26" xml:lang="en"><dl id="n2" title="2" class="3"><dt id="n3" title="3" class="1">dt</dt><dd id="n4" title="4" class="2">dd</dd></dl><center id="n5" title="5" class="22"><h1 id="n6" title="6" class="6"><em id="n7" title="7" class="4">em</em><strong id="n8" title="8" class="5">strong</strong></h1><h2 id="n9" title="9" class="9"><b id="n10" title="10" class="7">b</b><s id="n11" title="11" class="8">s</s></h2><blockquote id="n12" title="12" class="15"><!--blockquoteComment-->blockquoteText1:<br id="n13" title="13" class="10"/>blockquoteText2<p id="n14" title="14" class="13"><del id="n15" title="15" class="11">del</del><ins id="n16" title="16" class="12">ins</ins></p><?pi name="value"?><font id="n17" title="17" class="14" face="n8 n26">font</font></blockquote><h3 id="n18" title="18" class="18"><dfn id="n19" title="19" class="16">dfn</dfn><a id="n20" title="20" class="17">a</a></h3><h4 id="n21" title="21" class="21"><sub id="n22" title="22" class="19">sub</sub><sup id="n23" title="23" class="20">sup</sup></h4></center><span id="n24" title="24" class="25"><abbr id="n25" title="25" class="23">abbr</abbr><q id="n26" title="26" class="24" cite="n8 n17" xml:lang="it">q</q></span></div></body>
</html>