xpath-functional-test.html revision 5f90462bbf4efb0ac7bb65a852d5559d0ab30f0b
1<html>
2 <head>
3  <title>XPath Test</title>
4  <script>
5    if (window.layoutTestController)
6        layoutTestController.dumpAsText();
7
8    function test(expression, expect) {
9        function error(message) {
10            var e = Error();
11            e.result = result;
12            e.expects = expects;
13            e.expression = expression;
14            e.message = message;
15            return e
16        };
17        var result = document.evaluate(expression, document.body, null, 7, null);
18        var expects = expect.split(/\s+/);
19        for (var i = 0, l = expects.length; i < l; i++) if (expects[i] == '') expects.splice(i, 1);
20        if (result.snapshotLength != expects.length) throw error();
21        for (var i = 0, l = expects.length; i < l; i++) {
22            var expect = expects[i];
23            var r = expect.match(/^(?:([atpc]):)?(.*)$/);
24            var node = result.snapshotItem(i);
25            if (!types[r[1] || ''](node, r[2])) throw error();
26        }
27        return true;
28    };
29    window.onload = function() {
30        var ul = document.createElement('ul');
31        for (var i = 0, l = data.length; i < l; i ++) {
32            var li = document.createElement('li');
33            try {
34                test.apply(null, data[i]);
35                li.appendChild(document.createTextNode('[ok]' + data[i][0]));
36                li.className = 'ok';
37                li.style.color = 'green';
38            }
39            catch (e) {
40                li.appendChild(document.createTextNode('[ng]' + data[i][0]));
41                li.className = 'ng';
42                li.style.color = 'red';
43            }
44            ul.appendChild(li);
45        }
46        document.body.insertBefore(ul, document.body.firstChild);
47    };
48    var types = {
49        a: function(node, expect) {
50            var r = expect.split(':');
51            return r[0] == node.nodeName && r[1] == node.nodeValue;
52        },
53        t: function(node, expect) {
54            return expect == node.nodeValue;
55        },
56        p: function(node, expect) {
57            return expect == node.nodeName;
58        },
59        c: function(node, expect) {
60            return expect == node.nodeValue;
61        },
62        '': function(node, expect) {
63            return expect.toLowerCase() == node.nodeName.toLowerCase();
64        }
65    };
66    var data = [
67        ['.//blockquote/*', 'br p font'],
68        ['.//blockquote/child::*', 'br p font'],
69        ['.//blockquote/parent::*', 'center'],
70        ['.//blockquote/descendant::*', 'br p del ins font'],
71        ['.//blockquote/descendant-or-self::*', 'blockquote br p del ins font'],
72        ['.//blockquote/ancestor::*', 'html body div center'],
73        ['.//blockquote/ancestor-or-self::*', 'html body div center blockquote'],
74        ['.//blockquote/following-sibling::*', 'h3 h4'],
75        ['.//blockquote/preceding-sibling::*', 'h1 h2'],
76        ['.//blockquote/following::*', 'h3 dfn a h4 sub sup span abbr q'],
77        ['.//blockquote/preceding::*', 'head title script dl dt dd h1 em strong h2 b s'],
78        ['.//blockquote/self::*', 'blockquote'],
79        ['.//blockquote/attribute::id/parent::*', 'blockquote'],
80        ['.//blockquote/@id/parent::*', 'blockquote'],
81
82
83        ['.//*[blockquote]', 'center'],
84        ['.//*[child::blockquote]', 'center'],
85        ['.//*[parent::blockquote]', 'br p font'],
86        ['.//*[descendant::blockquote]', 'div center'],
87        ['.//*[descendant-or-self::blockquote]', 'div center blockquote'],
88        ['.//*[ancestor::blockquote]', 'br p del ins font'],
89        ['.//*[ancestor-or-self::blockquote]', 'blockquote br p del ins font'],
90        ['.//*[following-sibling::blockquote]', 'h1 h2'],
91        ['.//*[preceding-sibling::blockquote]', 'h3 h4'],
92        ['.//*[following::blockquote]', 'dl dt dd h1 em strong h2 b s'],
93        ['.//*[preceding::blockquote]', 'h3 dfn a h4 sub sup span abbr q'],
94        ['.//*[self::blockquote]', 'blockquote'],
95        ['.//*[@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'],
96        ['.//*[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'],
97
98
99        ['.//blockquote/text()', 't:blockquoteText1: t:blockquoteText2'],
100        ['.//blockquote/comment()', 'c:blockquoteComment'],
101        ['.//blockquote/processing-instruction()', 'p:pi'],
102        ['.//blockquote/processing-instruction("pi")', 'p:pi'],
103        ['.//blockquote/node()', 'c:blockquoteComment t:blockquoteText1: br t:blockquoteText2 p p:pi font'],
104        ['.//blockquote/p', 'p'],
105        ['.//blockquote/*', 'br p font'],
106
107
108        ['.//*[child::* and preceding::font]', 'h3 h4 span'],
109        ['.//*[not(child::*) and preceding::font]', 'dfn a sub sup abbr q'],
110        ['.//*[preceding::blockquote or following::blockquote]', 
111                            'dl dt dd h1 em strong h2 b s h3 dfn a h4 sub sup span abbr q'],
112        ['.//blockquote/ancestor::* | .//blockquote/descendant::*', 'html body div center br p del ins font'],
113        ['.//*[.="sub"]', 'sub'],
114        ['.//*[@title > 12 and @class < 15]', 'br p del ins font'], 
115        ['.//*[@title != @class]',
116                'div dl dt dd center em strong b s blockquote br p del ins font dfn a sub sup span abbr q'], 
117        ['.//*[((@class * @class + @title * @title) div (@class + @title)) > ((@class - @title) * (@class - @title))]',
118                'dl h1 h2 s blockquote br p font h3 dfn a h4 sub sup span abbr q'],
119        ['.//*[@title mod 2 = 0]', 'dl dd h1 strong b blockquote p ins h3 a sub span q'],
120
121
122        ['.//blockquote/child::*[last()]', 'font'],
123        ['.//blockquote/descendant::*[position() < 4]', 'br p del'],
124        ['id(.//font/@face)', 'strong q'],
125        ['.//*[name(.) = "sub"]', 'sub'],
126        ['.//*[name() = "sub"]', 'sub'],
127
128
129        ['.//blockquote/child::*[2]', 'p'],
130        ['.//blockquote/descendant::*[4]', 'ins'],
131        ['.//blockquote/descendant-or-self::*[4]', 'del'],
132        ['.//blockquote/ancestor::*[2]', 'div'],
133        ['.//blockquote/ancestor-or-self::*[2]', 'center'],
134        ['.//blockquote/following-sibling::*[1]', 'h3'],
135        ['.//blockquote/preceding-sibling::*[1]', 'h2'],
136        ['.//blockquote/following::*[4]', 'h4'],
137        ['.//blockquote/preceding::*[4]', 'strong'],
138
139        
140        ['.//*[starts-with(.,"s")]', 'strong s h4 sub sup'],
141        ['.//*[string(@title - 1) = "0"]', 'div'],
142        ['.//*[string() = "sub"]', 'sub'],
143        ['.//*[string(.) = "sub"]', 'sub'],
144        ['.//*[concat(.,..) = "subsubsup"]', 'sub'],
145        ['.//node()[concat(.,..,../..) = "bbbs"]', 't:b'],
146        ['.//*[starts-with(.,"s")]', 'strong s h4 sub sup'],
147        ['.//*[substring-before(.,"u") = "s"]', 'h4 sub sup'],
148        ['.//*[substring-after(.,"on") = "t"]', 'blockquote font'],
149        ['.//*[substring(.,2,1) = "u"]', 'h4 sub sup'],
150        ['.//*[substring(.,2) = "up"]', 'sup'],
151        ['.//*[contains(.,"b")]', 'div center h2 b blockquote h4 sub span abbr'],
152        ['.//*[string-length() = 3]', 'del ins dfn sub sup'],
153        ['.//*[string-length(.) = 3]', 'del ins dfn sub sup'],
154        ['.//*[.=translate(normalize-space("  s  u  b  ")," ","")]', 'sub'],
155        ['.//*[normalize-space()="q"]', 'q'],
156
157
158        ['.//*[boolean(@title - 1) = false()]', 'div'],
159        ['.//*[not(@title - 1) = true()]', 'div'],
160        ['.//*[lang("it")]', 'q'],
161
162
163        ['.//*[number(@title) < number(@class)]', 'div dl center blockquote span'],
164        ['.//*[sum(ancestor::*/@title) < sum(descendant::*/@title)]',
165                'div dl center h1 h2 blockquote p h3 h4 span'],
166        ['.//*[floor(@title div @class) = 1]',
167                'h1 em strong h2 b s br p del ins font h3 dfn a h4 sub sup abbr q'],
168        ['.//*[ceiling(@title div @class) = 1]', 'div dl center h1 h2 blockquote h3 h4 span'],
169        ['.//*[round(@title div @class) = 1]',
170                'dl h1 h2 b s blockquote br p del ins font h3 dfn a h4 sub sup span abbr q'],
171
172
173        ['.//*[blockquote]', 'center']
174    ];
175  </script>
176 </head>
177 <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>
178</html>
179