Skip to content

Commit d28153c

Browse files
authored
Merge pull request #902 from joewiz/xqsuite-assertxpath
[xqsuite] Flesh out docs for %test:assertXPath annotation
2 parents c3c7081 + 5f2fa3c commit d28153c

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

src/main/xar-resources/data/xqsuite/xqsuite.xml

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<article version="5.0" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
44
<info>
55
<title>XQSuite - Annotation-based Test Framework for XQuery</title>
6-
<date>3Q22</date>
6+
<date>1Q23</date>
77
<keywordset>
88
<keyword>application-development</keyword>
99
<keyword>testing</keyword>
@@ -158,10 +158,38 @@
158158
<code>%test:assertXPath($path-as-string)</code>
159159
</term>
160160
<listitem>
161-
<para>Tests if the return value of the tested function using the given XPath expression.</para>
162-
<para>The annotation value is executed as an XPath expression. The assert passes if the XPath expression returns a non-empty sequence or a single atomic item whose effective boolean value is true. Within the XPath expression, the variable
163-
<code>$result</code>
164-
contains a reference to the result sequence returned by the tested function.</para>
161+
<para>Tests if the return value of the tested function using the given XPath expression. The annotation value is executed as an XPath expression. The assertion passes if the XPath expression returns a non-empty sequence or a single atomic item whose effective boolean value is true.</para>
162+
<itemizedlist>
163+
<listitem>
164+
<para>Within the XPath expression, you may refer to the sequence of items returned by
165+
the tested function using the variable <code>$result</code>. For example, if the
166+
result returns the element <code>&lt;x/&gt;</code>, you can test for this result with
167+
the annotation <code>%test:assertXPath("$result/self::x")</code>. If the result
168+
returns <code>&lt;x&gt;&lt;y/&gt;&lt;/x&gt;</code>, the presence of the
169+
<code>&lt;y&gt;</code> element can be tested with the annotation expression
170+
<code>%test:assertXPath("$result/y")</code></para>
171+
</listitem>
172+
<listitem>
173+
<para>When selecting nodes with namespaces, use the namespace prefixes defined in the
174+
result sequence. For example, if the result returns an element <code>&lt;foo:x
175+
xmlns:foo="bar"/&gt;</code>, the annotation can test for this result with
176+
<code>%test:assertXPath("$result/self::foo:x")</code>.</para>
177+
</listitem>
178+
<listitem>
179+
<para>If the result contains node with a default namespace declaration, XQSuite
180+
assigns that namespace as the default element namespace for the annotation. For
181+
example, a result <code>&lt;x xmlns="foo"/&gt;</code> can be tested with the
182+
annotation <code>%test:assertXPath("$result/self::x")</code>.</para>
183+
</listitem>
184+
<listitem>
185+
<para>When selecting a result's descendant nodes that are assigned yet a different
186+
default namespace declaration, address these via namespace wildcard or "braced URI
187+
literal" notation. For example, the <code>&lt;y&gt;</code> element in the result
188+
<code>&lt;x xmlns="foo"&gt;&lt;y xmlns="bar"/&gt;&lt;/x&gt;</code> can be tested
189+
with the annotation <code>%test:assertXPath("$result/*:y")</code> or
190+
<code>%test:assertXPath("$result/Q{bar}y")</code>.</para>
191+
</listitem>
192+
</itemizedlist>
165193
</listitem>
166194
</varlistentry>
167195
<varlistentry>

0 commit comments

Comments
 (0)