Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #119 from wolfgangmm/develop

XQuery tests: namespaces fix
  • Loading branch information...
commit 8b4ad796a1d78e984c12540acec532ed16ebfb02 2 parents fd4f7e8 + 69cb056
@shabanovd shabanovd authored
View
23 src/org/exist/xquery/lib/xqsuite/xqsuite.xql
@@ -594,12 +594,31 @@ declare %private function test:assertXPath($annotation as element(annotation), $
util:expand($output)
else
$output
+ let $prolog :=
+ if ($result instance of element()*) then
+ let $namespaces := fold-left(function ($namespaces as map(*), $xml as element()) {
+ map:new(($namespaces,
+ for $prefix in in-scope-prefixes($xml)
+ where $prefix != "" and $prefix != "xml"
+ return
+ map:entry($prefix, namespace-uri-for-prefix($prefix, $xml))
+ ))
+ }, map:new(), $result/descendant-or-self::*)
+ return
+ string-join(
+ for $prefix in map:keys($namespaces)
+ return
+ "declare namespace " || $prefix || "='" || $namespaces($prefix) || "';",
+ " "
+ )
+ else
+ ()
let $xr :=
test:checkXPathResult(
if (matches($expr, "^\s*/")) then
- util:eval(concat("$result", $expr))
+ util:eval($prolog || "$result" || $expr)
else
- util:eval($expr)
+ util:eval($prolog || $expr)
)
return
if ($xr) then
View
46 test/src/xquery/xqsuite/xqsuite-tests.xql
@@ -0,0 +1,46 @@
+xquery version "3.0";
+
+(:~
+ : Some tests on features of the test suite itself.
+ :)
+module namespace t="http://exist-db.org/xquery/test/xqsuite";
+
+declare namespace test="http://exist-db.org/xquery/xqsuite";
+
+declare
+ %test:assertXPath("/name[. = 'Item1']")
+function t:xpath() {
+ <item>
+ <name>Item1</name>
+ </item>
+};
+
+declare
+ %test:assertXPath("/t:name[. = 'Item1']")
+function t:xpath-with-namespace() {
+ <t:item>
+ <t:name>Item1</t:name>
+ </t:item>
+};
+
+declare
+ %test:assertXPath("/t:name/x:id[. = 'abc']")
+function t:xpath-with-different-namespaces() {
+ <t:item>
+ <t:name><x:id xmlns:x="http://test.com/x">abc</x:id></t:name>
+ </t:item>
+};
+
+declare
+ %test:assertXPath("declare namespace f='http://foo.com'; $result//f:name[. = 'Item1']")
+function t:xpath-with-default-namespace() {
+ <item xmlns="http://foo.com">
+ <name>Item1</name>
+ </item>
+};
+
+declare
+ %test:assertXPath("string-length($result) = 5")
+function t:xpath-atomic-value() {
+ "Hello"
+};
Please sign in to comment.
Something went wrong with that request. Please try again.