Skip to content

Commit 91bb93e

Browse files
committed
[test] Tests to show that Path expression with nested positional predicate succeeds on database node
Closes #1892
1 parent eb725f9 commit 91bb93e

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

exist-core/src/test/xquery/npt.xqm

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
(:
2+
: eXist-db Open Source Native XML Database
3+
: Copyright (C) 2001 The eXist-db Authors
4+
:
5+
6+
: http://www.exist-db.org
7+
:
8+
: This library is free software; you can redistribute it and/or
9+
: modify it under the terms of the GNU Lesser General Public
10+
: License as published by the Free Software Foundation; either
11+
: version 2.1 of the License, or (at your option) any later version.
12+
:
13+
: This library is distributed in the hope that it will be useful,
14+
: but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
: Lesser General Public License for more details.
17+
:
18+
: You should have received a copy of the GNU Lesser General Public
19+
: License along with this library; if not, write to the Free Software
20+
: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21+
:)
22+
xquery version "3.1";
23+
24+
module namespace npt="http://exist-db.org/test/nested-positional-predicate";
25+
26+
declare namespace test="http://exist-db.org/xquery/xqsuite";
27+
28+
declare variable $npt:DATA :=
29+
document {
30+
<xml>
31+
<a>
32+
<b>B1</b>
33+
</a>
34+
<a>
35+
<b>B2</b>
36+
<c>correct</c>
37+
</a>
38+
<a>
39+
<b>B3</b>
40+
<c>wrong</c>
41+
</a>
42+
</xml>
43+
};
44+
45+
declare
46+
%test:setUp
47+
function npt:setup() {
48+
xmldb:create-collection("/db", "test"),
49+
xmldb:store("/db/test", "test.xml", $npt:DATA)
50+
};
51+
52+
declare
53+
%test:tearDown
54+
function npt:cleanup() {
55+
xmldb:remove("/db/test")
56+
};
57+
58+
declare
59+
%test:assertEquals("<result><c>correct</c><c>wrong</c></result>")
60+
function npt:in-memory() {
61+
<result>{$npt:DATA//c[../preceding-sibling::a]}</result>
62+
};
63+
64+
declare
65+
%test:assertEquals("<result><c>correct</c><c>wrong</c></result>")
66+
function npt:in-database() {
67+
<result>{doc("/db/test/test.xml")//c[../preceding-sibling::a]}</result>
68+
};
69+
70+
71+
declare
72+
%test:assertEquals("<result><c>correct</c><c>wrong</c></result>")
73+
function npt:in-memory-predicate() {
74+
<result>{$npt:DATA//c[../preceding-sibling::a[1]]}</result>
75+
};
76+
77+
declare
78+
%test:assertEquals("<result><c>correct</c><c>wrong</c></result>")
79+
function npt:in-database-predicate() {
80+
<result>{doc("/db/test/test.xml")//c[../preceding-sibling::a[1]]}</result>
81+
};
82+
83+
declare
84+
%test:assertEquals("<result><c>correct</c><c>wrong</c></result>")
85+
function npt:in-memory-position() {
86+
<result>{$npt:DATA//c[../preceding-sibling::a[position() eq 1]]}</result>
87+
};
88+
89+
declare
90+
%test:assertEquals("<result><c>correct</c><c>wrong</c></result>")
91+
function npt:in-database-position() {
92+
<result>{doc("/db/test/test.xml")//c[../preceding-sibling::a[position() eq 1]]}</result>
93+
};
94+
95+
declare
96+
%test:assertEquals("<result><c>correct</c></result>")
97+
function npt:in-memory-predicate-and-path() {
98+
<result>{$npt:DATA//c[../preceding-sibling::a[1]/b = 'B1']}</result>
99+
};
100+
101+
declare
102+
%test:assertEquals("<result><c>correct</c></result>")
103+
function npt:in-database-predicate-and-path() {
104+
<result>{doc("/db/test/test.xml")//c[../preceding-sibling::a[1]/b = 'B1']}</result>
105+
};
106+
107+
declare
108+
%test:assertEquals("<result><c>correct</c></result>")
109+
function npt:in-memory-position-and-path() {
110+
<result>{$npt:DATA//c[../preceding-sibling::a[position() eq 1]/b = 'B1']}</result>
111+
};
112+
113+
declare
114+
%test:assertEquals("<result><c>correct</c></result>")
115+
function npt:in-database-position-and-path() {
116+
<result>{doc("/db/test/test.xml")//c[../preceding-sibling::a[position() eq 1]/b = 'B1']}</result>
117+
};

0 commit comments

Comments
 (0)