summaryrefslogtreecommitdiffstats
path: root/LayoutTests/fast/xpath/ambiguous-operators.html
blob: f22a18572294caa077fe64f63b5409eab0b950d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<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>
<style>
#context {display:none}
</style>
</head>
<body>
<p>Test that an NCName and * are interpreted as an operator when in
binary operator context, and as a NameTest otherwise.

<p>See <a href="http://bugs.webkit.org/show_bug.cgi?id=50366">bug 50366</a>:
XPath lexer misinterprets expression starting with "div".</p>

<div id="console"></div>

<div id="context">
  <div id="two" div="x">2</div>
</div>

<script>
var context = document.getElementById('context');
var div = document.getElementById('two');

// =========== div ===========

test(document, context, "div", [div], null);  // div with no preceding token
test(document, context, "  div", [div], null);
// div following every possible [28] ExprToken http://www.w3.org/TR/xpath/
test(document, context, "(div) div (div)", 2/2, null);  // div after ( and )
test(document, context, "self::node()[div] div 1", 2/1, null);  // div after [ and ]
test(document, context, ". div .", 2/2, null);  // div after .
test(document, div, ".. div ..", 2/2, null);  // div after ..
test(document, context, "string(div/@div)", "x", null);  // div after @
test(document, context, "substring-before('1992', div)", "199", null);  // div after ,
test(document, div, "self::div", [div], null);  // div after ::
test(document, context, "* div 4", 2/4, null);  // div after NameTest *
test(document, context, "'3' div 4", 3/4, null);  // div after Literal
test(document, context, "\"3\" div 4", 3/4, null);  // div after Literal
test(document, context, "12 div 4", 12/4, null);  // div after Number

// div following every [32] Operator
test(document, context, "true() and div", true, null);  // div after OperatorName and
test(document, context, "false() or div", true, null);  // div after OperatorName or
test(document, context, "div mod div", 0, null);  // div after OperatorName mod
test(document, context, "div div div", 1, null);  // div after OperatorName div
test(document, context, "3 * div", 6, null);  // div after MultiplyOperator
test(document, context, "div/div", [], null);  // div after /
test(document, context, "div//div", [], null);  // div after //
test(document, context, "zz|div", [div], null);  // div after |
test(document, context, "div+div", 4, null);  // div after +
test(document, context, "- - div", 2, null);  // div after unary -
test(document, context, "5 -div", 3, null);  // div after binary -
test(document, context, "div=div", true, null);  // div after =
test(document, context, "div!=div", false, null);  // div after =
test(document, context, "div<div", false, null);  // div after <
test(document, context, "div<=div", true, null);  // div after <=
test(document, context, "div>div", false, null);  // div after >
test(document, context, "div>=div", true, null);  // div after >=


// =========== * ===========

test(document, context, "*", [div], null);  // * with no preceding token
test(document, context, "  *", [div], null);
// * following every possible [28] ExprToken http://www.w3.org/TR/xpath/
test(document, context, "(*) * (*)", 2*2, null);  // * after ( and )
test(document, context, "self::node()[*] * 1", 2*1, null);  // * after [ and ]
test(document, context, ". * .", 2*2, null);  // * after .
test(document, div, ".. * ..", 2*2, null);  // * after ..
// (* can't follow @)
test(document, context, "substring-before('1992', *)", "199", null);  // * after ,
test(document, div, "self::*", [div], null);  // * after ::
test(document, context, "* * 4", 2*4, null);  // * after NameTest *
test(document, context, "'3' * 4", 3*4, null);  // * after Literal
test(document, context, "\"3\" * 4", 3*4, null);  // * after Literal
test(document, context, "12 * 4", 12*4, null);  // * after Number

// * following every [32] Operator
test(document, context, "true() and *", true, null);  // * after OperatorName and
test(document, context, "false() or *", true, null);  // * after OperatorName or
test(document, context, "* mod *", 0, null);  // * after OperatorName mod
test(document, context, "* div *", 1, null);  // * after OperatorName div
test(document, context, "3 * *", 6, null);  // * after MultiplyOperator
test(document, context, "*/*", [], null);  // * after /
test(document, context, "*//*", [], null);  // * after //
test(document, context, "zz|*", [div], null);  // * after |
test(document, context, "*+*", 4, null);  // * after +
test(document, context, "- - *", 2, null);  // * after unary -
test(document, context, "5 -*", 3, null);  // * after binary -
test(document, context, "*=*", true, null);  // * after =
test(document, context, "*!=*", false, null);  // * after =
test(document, context, "*<*", false, null);  // * after <
test(document, context, "*<=*", true, null);  // * after <=
test(document, context, "*>*", false, null);  // * after >
test(document, context, "*>=*", true, null);  // * after >=

var xmlDoc = (new DOMParser).parseFromString("<or xmlns='uri'>5</or>", "text/xml");
var nsResolver = function(prefix) {return 'uri';}
// div and * after :
test(xmlDoc, xmlDoc, "or:or", [xmlDoc.documentElement], nsResolver);
test(xmlDoc, xmlDoc, "or:*", [xmlDoc.documentElement], nsResolver);

// A few tests with mod as well
var xmlDoc2 = (new DOMParser).parseFromString("<mod and='x'>8</mod>", "text/xml");
test(xmlDoc2, xmlDoc2, "mod", [xmlDoc2.documentElement], null);
test(xmlDoc2, xmlDoc2, "mod mod mod", 0, null);
test(xmlDoc2, xmlDoc2, "(mod) mod 5", 3, null);
test(xmlDoc2, xmlDoc2, "string(mod/@and)", 'x', null);


var successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>