Skip to content

Commit

Permalink
Merge pull request #683 from ndw/p-compare-tests
Browse files Browse the repository at this point in the history
Add tests for p:compare
  • Loading branch information
ndw authored Mar 28, 2024
2 parents c8c60ef + 9e0aa7f commit 5b274cc
Show file tree
Hide file tree
Showing 6 changed files with 355 additions and 0 deletions.
66 changes: 66 additions & 0 deletions test-suite/tests/nw-compare-001.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
xmlns:err="http://www.w3.org/ns/xproc-error"
expected="pass">
<t:info>
<t:title>p:compare 001 (NW)</t:title>
<t:revision-history>
<t:revision>
<t:date>2024-03-26</t:date>
<t:author>
<t:name>Norm Tovey-Walsh</t:name>
</t:author>
<t:description xmlns="http://www.w3.org/1999/xhtml">
<p>Created test for p:compare.</p>
</t:description>
</t:revision>
</t:revision-history>
</t:info>
<t:description xmlns="http://www.w3.org/1999/xhtml">
<p>Check if p:compare succeeds when the documents are identical.</p>
</t:description>
<t:pipeline>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:test="http://test" version="3.0">
<p:output port="result">
<p:pipe step="compare" port="result"/>
</p:output>

<p:identity name="doc-a">
<p:with-input>
<doc>
<element name="first"/>
<element/>
</doc>
</p:with-input>
</p:identity>

<p:identity name="doc-b">
<p:with-input>
<doc>
<element name="first"/>
<element/>
</doc>
</p:with-input>
</p:identity>

<p:compare name="compare">
<p:with-input port="source" pipe="@doc-a"/>
<p:with-input port="alternate" pipe="@doc-b"/>
</p:compare>

</p:declare-step>
</t:pipeline>
<t:schematron>
<s:schema queryBinding="xslt2"
xmlns:s="http://purl.oclc.org/dsdl/schematron"
xmlns="http://www.w3.org/1999/xhtml">
<s:ns prefix="c" uri="http://www.w3.org/ns/xproc-step"/>
<s:pattern>
<s:rule context="/">
<s:assert test="c:result">Root element is not 'c:result'.</s:assert>
<s:assert test="string(c:result)='true'">Result is not ‘true’.</s:assert>
</s:rule>
</s:pattern>
</s:schema>
</t:schematron>
</t:test>
66 changes: 66 additions & 0 deletions test-suite/tests/nw-compare-002.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
xmlns:err="http://www.w3.org/ns/xproc-error"
expected="pass">
<t:info>
<t:title>p:compare 002 (NW)</t:title>
<t:revision-history>
<t:revision>
<t:date>2024-03-26</t:date>
<t:author>
<t:name>Norm Tovey-Walsh</t:name>
</t:author>
<t:description xmlns="http://www.w3.org/1999/xhtml">
<p>Created test for p:compare.</p>
</t:description>
</t:revision>
</t:revision-history>
</t:info>
<t:description xmlns="http://www.w3.org/1999/xhtml">
<p>Check if p:compare fails when the documents are different.</p>
</t:description>
<t:pipeline>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:test="http://test" version="3.0">
<p:output port="result">
<p:pipe step="compare" port="result"/>
</p:output>

<p:identity name="doc-a">
<p:with-input>
<doc>
<element name="first"/>
<element/>
</doc>
</p:with-input>
</p:identity>

<p:identity name="doc-b">
<p:with-input>
<doc>
<element name="second"/>
<element/>
</doc>
</p:with-input>
</p:identity>

<p:compare name="compare">
<p:with-input port="source" pipe="@doc-a"/>
<p:with-input port="alternate" pipe="@doc-b"/>
</p:compare>

</p:declare-step>
</t:pipeline>
<t:schematron>
<s:schema queryBinding="xslt2"
xmlns:s="http://purl.oclc.org/dsdl/schematron"
xmlns="http://www.w3.org/1999/xhtml">
<s:ns prefix="c" uri="http://www.w3.org/ns/xproc-step"/>
<s:pattern>
<s:rule context="/">
<s:assert test="c:result">Root element is not 'c:result'.</s:assert>
<s:assert test="string(c:result)='false'">Result is not ‘false’.</s:assert>
</s:rule>
</s:pattern>
</s:schema>
</t:schematron>
</t:test>
66 changes: 66 additions & 0 deletions test-suite/tests/nw-compare-003.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
xmlns:err="http://www.w3.org/ns/xproc-error"
expected="pass">
<t:info>
<t:title>p:compare 003 (NW)</t:title>
<t:revision-history>
<t:revision>
<t:date>2024-03-26</t:date>
<t:author>
<t:name>Norm Tovey-Walsh</t:name>
</t:author>
<t:description xmlns="http://www.w3.org/1999/xhtml">
<p>Created test for p:compare.</p>
</t:description>
</t:revision>
</t:revision-history>
</t:info>
<t:description xmlns="http://www.w3.org/1999/xhtml">
<p>Check if p:compare succeeds when the documents are identical if fail-if-not-equal is true.</p>
</t:description>
<t:pipeline>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:test="http://test" version="3.0">
<p:output port="result">
<p:pipe step="compare" port="result"/>
</p:output>

<p:identity name="doc-a">
<p:with-input>
<doc>
<element name="first"/>
<element/>
</doc>
</p:with-input>
</p:identity>

<p:identity name="doc-b">
<p:with-input>
<doc>
<element name="first"/>
<element/>
</doc>
</p:with-input>
</p:identity>

<p:compare name="compare" fail-if-not-equal="true">
<p:with-input port="source" pipe="@doc-a"/>
<p:with-input port="alternate" pipe="@doc-b"/>
</p:compare>

</p:declare-step>
</t:pipeline>
<t:schematron>
<s:schema queryBinding="xslt2"
xmlns:s="http://purl.oclc.org/dsdl/schematron"
xmlns="http://www.w3.org/1999/xhtml">
<s:ns prefix="c" uri="http://www.w3.org/ns/xproc-step"/>
<s:pattern>
<s:rule context="/">
<s:assert test="c:result">Root element is not 'c:result'.</s:assert>
<s:assert test="string(c:result)='true'">Result is not ‘true’.</s:assert>
</s:rule>
</s:pattern>
</s:schema>
</t:schematron>
</t:test>
54 changes: 54 additions & 0 deletions test-suite/tests/nw-compare-004.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
xmlns:err="http://www.w3.org/ns/xproc-error"
expected="fail" code="err:XC0019">
<t:info>
<t:title>p:compare 004 (NW)</t:title>
<t:revision-history>
<t:revision>
<t:date>2024-03-26</t:date>
<t:author>
<t:name>Norm Tovey-Walsh</t:name>
</t:author>
<t:description xmlns="http://www.w3.org/1999/xhtml">
<p>Created test for p:compare.</p>
</t:description>
</t:revision>
</t:revision-history>
</t:info>
<t:description xmlns="http://www.w3.org/1999/xhtml">
<p>Check if p:compare raises an error when the documents are different and
fail-if-not-equal is true.</p>
</t:description>
<t:pipeline>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:test="http://test" version="3.0">
<p:output port="result">
<p:pipe step="compare" port="result"/>
</p:output>

<p:identity name="doc-a">
<p:with-input>
<doc>
<element name="first"/>
<element/>
</doc>
</p:with-input>
</p:identity>

<p:identity name="doc-b">
<p:with-input>
<doc>
<element name="second"/>
<element/>
</doc>
</p:with-input>
</p:identity>

<p:compare name="compare" fail-if-not-equal="true">
<p:with-input port="source" pipe="@doc-a"/>
<p:with-input port="alternate" pipe="@doc-b"/>
</p:compare>

</p:declare-step>
</t:pipeline>
</t:test>
53 changes: 53 additions & 0 deletions test-suite/tests/nw-compare-005.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
xmlns:err="http://www.w3.org/ns/xproc-error"
expected="fail" code="err:XC0076">
<t:info>
<t:title>p:compare 005 (NW)</t:title>
<t:revision-history>
<t:revision>
<t:date>2024-03-26</t:date>
<t:author>
<t:name>Norm Tovey-Walsh</t:name>
</t:author>
<t:description xmlns="http://www.w3.org/1999/xhtml">
<p>Created test for p:compare.</p>
</t:description>
</t:revision>
</t:revision-history>
</t:info>
<t:description xmlns="http://www.w3.org/1999/xhtml">
<p>Check if p:compare raises an error when the method is unsupported.</p>
</t:description>
<t:pipeline>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:test="http://test" version="3.0">
<p:output port="result">
<p:pipe step="compare" port="result"/>
</p:output>

<p:identity name="doc-a">
<p:with-input>
<doc>
<element name="first"/>
<element/>
</doc>
</p:with-input>
</p:identity>

<p:identity name="doc-b">
<p:with-input>
<doc>
<element name="second"/>
<element/>
</doc>
</p:with-input>
</p:identity>

<p:compare name="compare" method="an-unsupported-value">
<p:with-input port="source" pipe="@doc-a"/>
<p:with-input port="alternate" pipe="@doc-b"/>
</p:compare>

</p:declare-step>
</t:pipeline>
</t:test>
50 changes: 50 additions & 0 deletions test-suite/tests/nw-compare-006.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
xmlns:err="http://www.w3.org/ns/xproc-error"
expected="fail" code="err:XC0077">
<t:info>
<t:title>p:compare 006 (NW)</t:title>
<t:revision-history>
<t:revision>
<t:date>2024-03-26</t:date>
<t:author>
<t:name>Norm Tovey-Walsh</t:name>
</t:author>
<t:description xmlns="http://www.w3.org/1999/xhtml">
<p>Created test for p:compare.</p>
</t:description>
</t:revision>
</t:revision-history>
</t:info>
<t:description xmlns="http://www.w3.org/1999/xhtml">
<p>Check if p:compare raises an error when the documents cannot be compared.</p>
</t:description>
<t:pipeline>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:test="http://test" version="3.0">
<p:output port="result">
<p:pipe step="compare" port="result"/>
</p:output>

<p:identity name="doc-a">
<p:with-input>
<p:inline content-type="text/plain">Not XML.</p:inline>
</p:with-input>
</p:identity>

<p:identity name="doc-b">
<p:with-input>
<doc>
<element name="second"/>
<element/>
</doc>
</p:with-input>
</p:identity>

<p:compare name="compare">
<p:with-input port="source" pipe="@doc-a"/>
<p:with-input port="alternate" pipe="@doc-b"/>
</p:compare>

</p:declare-step>
</t:pipeline>
</t:test>

0 comments on commit 5b274cc

Please sign in to comment.