Skip to content

Commit

Permalink
test: test $x:xspec-uri variable more (xspec#1792)
Browse files Browse the repository at this point in the history
  • Loading branch information
galtm committed Dec 9, 2023
1 parent 9a8b77f commit ecad57a
Show file tree
Hide file tree
Showing 8 changed files with 324 additions and 4 deletions.
32 changes: 32 additions & 0 deletions test/catalog/01/imported-xspec-uri.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<t:description
query="x-urn:test:do-nothing"
query-at="do-nothing.xqm"
schematron="do-nothing.sch"
stylesheet="do-nothing.xsl"
xml:base="../../"
xmlns:im="x-urn:test:imported-xspec-uri"
xmlns:t="http://www.jenitennison.com/xslt/xspec"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<t:variable name="im:xspec-uri-in-global-var"
select="$t:xspec-uri"/>

<t:scenario label="$x:xspec-uri defined and checked in imported file">
<t:call function="true" />
<!-- Assertion fails when this test file runs and
passes when the importing file, xspec-uri.xspec, runs.
The regular expression is designed to match files named
catalog-01_xspec-uri.xspec and xspec-uri.xspec.
-->
<t:expect label="should be top-level .xspec file that is running"
test="ends-with($im:xspec-uri-in-global-var, '/catalog-01_xspec-uri.xspec')
or ends-with($im:xspec-uri-in-global-var, '/xspec-uri.xspec')" />
</t:scenario>

<t:scenario label="Store $x:xspec-uri in variable in imported file" shared="yes">
<t:variable name="im:xspec-uri-in-local-var"
select="$t:xspec-uri"/>
</t:scenario>

</t:description>
30 changes: 30 additions & 0 deletions test/catalog/catalog-01_xspec-uri.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<t:description
query="x-urn:test:do-nothing"
query-at="do-nothing.xqm"
schematron="do-nothing.sch"
stylesheet="do-nothing.xsl"
xml:base="../"
xmlns:im="x-urn:test:imported-xspec-uri"
xmlns:t="http://www.jenitennison.com/xslt/xspec"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<t:import href="catalog-01:/imported-xspec-uri.xspec" />
<t:scenario label="$x:xspec-uri accessed from code in XSpec files imported via XML Catalog">
<t:call function="true" />
<t:scenario label="in global variable">
<t:expect label="should use file:/, not catalog-01:/"
select="$im:xspec-uri-in-global-var => starts-with('file:')" />
<t:expect label="should equal the value defined in this importing file"
test="$im:xspec-uri-in-global-var eq $t:xspec-uri" />
</t:scenario>
<t:scenario label="in variable brought into importing file via x:like">
<t:like label="Store $x:xspec-uri in variable in imported file" />
<t:expect label="should use file:/, not catalog-01:/"
select="$im:xspec-uri-in-local-var => starts-with('file:')" />
<t:expect label="should equal the value defined in this importing file"
test="$im:xspec-uri-in-local-var eq $t:xspec-uri" />
</t:scenario>
</t:scenario>

</t:description>
33 changes: 33 additions & 0 deletions test/win-bats/collection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,39 @@
call :verify_line 23 x "passed: 4 / pending: 0 / failed: 0 / total: 4"
</case>

<!--
$x:xspec-uri with usage of catalog file (XML_CATALOG)
Test value of $x:xspec-uri with file imported via XML Catalog
-->

<case name="$x:xspec-uri with file imported via XML Catalog (XSLT)">
set "SAXON_CP=%SAXON_CP%;%APACHE_XMLRESOLVER_JAR%"
set "XML_CATALOG=catalog\01\catalog-rewriteURI.xml"

call :run ..\bin\xspec.bat "catalog\catalog-01_xspec-uri.xspec"
call :verify_retval 0
call :verify_line 19 x "passed: 5 / pending: 0 / failed: 0 / total: 5"
</case>

<case name="$x:xspec-uri with file imported via XML Catalog (XQuery)">
set "SAXON_CP=%SAXON_CP%;%APACHE_XMLRESOLVER_JAR%"
set "XML_CATALOG=catalog\01\catalog-rewriteURI.xml"

call :run ..\bin\xspec.bat -q "catalog\catalog-01_xspec-uri.xspec"
call :verify_retval 0
call :verify_line 9 x "passed: 5 / pending: 0 / failed: 0 / total: 5"
</case>

<case name="$x:xspec-uri with file imported via XML Catalog (Schematron)">
set "SAXON_CP=%SAXON_CP%;%APACHE_XMLRESOLVER_JAR%"
set "XML_CATALOG=catalog\01\catalog-rewriteURI.xml"

call :run ..\bin\xspec.bat -s "catalog\catalog-01_xspec-uri.xspec"
call :verify_retval 0
call :verify_line 24 x "passed: 5 / pending: 0 / failed: 0 / total: 5"
</case>

<!--
SAXON_HOME (CLI)
Expand Down
22 changes: 22 additions & 0 deletions test/xspec-uri.sch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<sch:schema queryBinding="xslt2"
xmlns:sch="http://purl.oclc.org/dsdl/schematron">
<sch:ns uri="http://www.jenitennison.com/xslt/xspec" prefix="x"/>

<sch:pattern>
<sch:let name="end-of-test-path" value="'/test/xspec-uri_schematron.xspec'" />
<sch:let name="xspec-description-id" value="'xspec-uri_schematron'" />

<sch:rule context="context-child">
<sch:report id="context-child-attr-ok" test="ends-with(@attr, $end-of-test-path)" />
<sch:report id="context-child-text-ok" test="ends-with(text(), $end-of-test-path)" />
</sch:rule>

<sch:rule context="x:description">
<sch:report id="context-select-ok"
test="string(@xml:id) eq $xspec-description-id"
>Identified xspec-uri_schematron.xspec by its /x:description/@xml:id</sch:report>
</sch:rule>

</sch:pattern>
</sch:schema>
96 changes: 92 additions & 4 deletions test/xspec-uri.xspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<t:description query="x-urn:test:do-nothing" query-at="do-nothing.xqm"
schematron="do-nothing.sch" stylesheet="do-nothing.xsl"
xmlns:t="http://www.jenitennison.com/xslt/xspec" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<t:description expand-text="1"
query="x-urn:test:do-nothing"
query-at="do-nothing.xqm"
schematron="do-nothing.sch"
stylesheet="do-nothing.xsl"
xmlns:im="x-urn:test:imported-xspec-uri"
xmlns:local="x-urn:test:xspec-uri"
xmlns:t="http://www.jenitennison.com/xslt/xspec"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<t:variable name="local:end-of-uri" as="xs:string"
select="'/test/xspec-uri.xspec'" />

<t:scenario label="$x:xspec-uri in x:call/x:param">
<t:call function="exactly-one">
<t:param select="$t:xspec-uri" />
</t:call>
<t:expect label="should be xs:anyURI" test="$t:result instance of xs:anyURI" />
<t:expect label="should be this .xspec file"
test="ends-with($t:result, '/test/xspec-uri.xspec')" />
test="$t:result => ends-with($local:end-of-uri)" />
<t:expect label="should be the same as the one in x:expect" select="$t:xspec-uri" />
</t:scenario>

<t:scenario label="$x:xspec-uri in x:expect">
<t:call function="true" />
<t:expect label="in @select, should be this .xspec file"
select="$t:xspec-uri => ends-with($local:end-of-uri)" />
<t:expect label="in Boolean @test, should be this .xspec file"
test="$t:xspec-uri => ends-with($local:end-of-uri)" />
<t:expect label="in user-content attribute, should be this .xspec file"
select="/*/@attr/xs:anyURI(.) => ends-with($local:end-of-uri)">
<element attr="{$t:xspec-uri}" />
</t:expect>
<t:expect label="in user-content text node, should be this .xspec file"
select="xs:anyURI(.) => ends-with($local:end-of-uri)">
<element>{$t:xspec-uri}</element>
</t:expect>
<t:scenario label="in filter @test">
<t:call function="one-or-more">
<t:param select="('/test/xspec-uri.xspec', 'non-match')"/>
</t:call>
<t:expect label="should be this .xspec file"
test="$t:result[ends-with($t:xspec-uri, .)]"
select="'/test/xspec-uri.xspec'" />
</t:scenario>
</t:scenario>

<t:variable name="local:xspec-uri-in-global-var"
select="$t:xspec-uri"/>
<t:variable name="local:xspec-uri-in-global-var-user-content">
<element attr="{$t:xspec-uri}">{$t:xspec-uri}</element>
</t:variable>
<t:scenario label="$x:xspec-uri in global x:variable">
<t:call function="true" />
<t:expect label="in @select, should be this .xspec file"
test="$local:xspec-uri-in-global-var => ends-with($local:end-of-uri)" />
<t:expect label="in user-content attribute, should be this .xspec file"
test="$local:xspec-uri-in-global-var-user-content/@attr/string()
=> xs:anyURI() => ends-with($local:end-of-uri)" />
<t:expect label="in user-content text node, should be this .xspec file"
test="$local:xspec-uri-in-global-var-user-content/string()
=> xs:anyURI() => ends-with($local:end-of-uri)" />
</t:scenario>

<t:scenario label="$x:xspec-uri in scenario-level x:variable">
<t:variable name="local:xspec-uri-in-scenario-var"
select="$t:xspec-uri"/>
<t:variable name="local:xspec-uri-in-scenario-var-user-content">
<element attr="{$t:xspec-uri}">{$t:xspec-uri}</element>
</t:variable>
<t:call function="true" />
<t:expect label="in @select, should be this .xspec file"
test="$local:xspec-uri-in-scenario-var => ends-with($local:end-of-uri)" />
<t:expect label="in user-content attribute, should be this .xspec file"
test="$local:xspec-uri-in-scenario-var-user-content/@attr/string()
=> xs:anyURI() => ends-with($local:end-of-uri)" />
<t:expect label="in user-content text node, should be this .xspec file"
test="$local:xspec-uri-in-scenario-var-user-content/string()
=> xs:anyURI() => ends-with($local:end-of-uri)" />
</t:scenario>

<!-- Import XSpec file here using relative path in @href.
test/catalog/catalog-01_xspec-uri.xspec will import the same
file using an XML Catalog reference in @href. -->
<t:import href="catalog/01/imported-xspec-uri.xspec"/>
<t:scenario label="$x:xspec-uri accessed from code in imported XSpec file">
<t:call function="true" />
<t:scenario label="in global variable">
<t:expect label="should be the importing .xspec file, not the imported one"
select="$im:xspec-uri-in-global-var => ends-with($local:end-of-uri)" />
<t:expect label="should equal the value defined in importing file"
test="$im:xspec-uri-in-global-var eq $t:xspec-uri" />
</t:scenario>
<t:scenario label="in variable brought into importing file via x:like">
<t:like label="Store $x:xspec-uri in variable in imported file" />
<t:expect label="should be the importing .xspec file, not the imported one"
select="$im:xspec-uri-in-local-var => ends-with($local:end-of-uri)" />
<t:expect label="should equal the value defined in importing file"
test="$im:xspec-uri-in-local-var eq $t:xspec-uri" />
</t:scenario>
</t:scenario>

</t:description>
37 changes: 37 additions & 0 deletions test/xspec-uri_schematron.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<t:description xml:id="xspec-uri_schematron"
schematron="xspec-uri.sch"
xmlns:local="x-urn:test:xspec-uri_schematron"
xmlns:t="http://www.jenitennison.com/xslt/xspec"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<!-- Note: /t:description/@xml:id is referenced in xspec-uri.sch -->

<t:scenario label="$x:xspec-uri in x:context user-content">
<t:context expand-text="1">
<context-child attr="{$t:xspec-uri}">{$t:xspec-uri}</context-child>
</t:context>
<t:expect-report id="context-child-attr-ok"/>
<t:expect-report id="context-child-text-ok"/>
</t:scenario>

<t:scenario label="$x:xspec-uri in x:context/@select">
<t:context select="$t:xspec-uri[. ne ''] => doc()" />
<t:expect-report id="context-select-ok"/>
</t:scenario>

<t:scenario label="Derived .xspec file's @original-xspec attribute">
<!-- Don't compute the derived .xspec file's URI from $x:xspec-uri
because run-xspec-tests-ant.* puts preprocessed files in a
temporary directory. However, the preprocessed .xsl and .xspec
files are together in that directory. -->
<t:variable name="local:sch-preproc-xspec-uri"
as="xs:string" select="$t:stylesheet-uri => replace('\.xsl$','.xspec')" />
<t:call function="xs:anyURI">
<t:param select="doc($local:sch-preproc-xspec-uri)/t:description/@original-xspec
=> exactly-one()" />
</t:call>
<t:expect label="should match $x:xspec-uri" select="$t:xspec-uri" />
</t:scenario>

</t:description>
45 changes: 45 additions & 0 deletions test/xspec-uri_stylesheet.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<t:description expand-text="1"
stylesheet="mirror.xsl"
xmlns:local="x-urn:test:xspec-uri_stylesheet"
xmlns:mirror="x-urn:test:mirror"
xmlns:t="http://www.jenitennison.com/xslt/xspec"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<t:variable name="local:end-of-uri" as="xs:string"
select="'/test/xspec-uri_stylesheet.xspec'" />

<t:scenario label="$x:xspec-uri in x:context/x:param">
<t:context mode="mirror:param-mirror">
<t:param name="param-items" select="$t:xspec-uri" />
<element />
</t:context>
<t:expect label="should be this .xspec file"
test="$t:result => ends-with($local:end-of-uri)" />
</t:scenario>

<t:scenario label="$x:xspec-uri in x:context user-content">
<t:context mode="mirror:context-mirror">
<element attr="{$t:xspec-uri}">{$t:xspec-uri}</element>
</t:context>
<t:expect label="in attribute value, should be this .xspec file"
test="$t:result/@attr => ends-with($local:end-of-uri)" />
<t:expect label="in text node, should be this .xspec file"
test="$t:result/text() => ends-with($local:end-of-uri)" />
</t:scenario>

<t:scenario label="$x:xspec-uri in x:context/@select">
<t:context mode="mirror:context-mirror"
select="$t:xspec-uri[. ne ''] => doc()" />
<t:expect label="should be this .xspec file"
test="$t:result => base-uri() => ends-with($local:end-of-uri)" />
</t:scenario>

<t:helper stylesheet="global-override.xsl" />
<t:param name="global-x-param_vs_xsl-param" select="$t:xspec-uri" />
<t:scenario label="$x:xspec-uri in x:description/x:param">
<t:context select="'global-x-param_vs_xsl-param'" />
<t:expect label="should be this .xspec file"
test="$t:result => ends-with($local:end-of-uri)" />
</t:scenario>
</t:description>
33 changes: 33 additions & 0 deletions test/xspec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,39 @@ load bats-helper
[ "${lines[22]}" = "passed: 4 / pending: 0 / failed: 0 / total: 4" ]
}

#
# $x:xspec-uri with usage of catalog file (XML_CATALOG)
#
# Test value of $x:xspec-uri with file imported via XML Catalog
#

@test "$x:xspec-uri with file imported via XML Catalog (XSLT)" {
export SAXON_CP="${SAXON_CP}:${APACHE_XMLRESOLVER_JAR}"
export XML_CATALOG="catalog/01/catalog-rewriteURI.xml"

myrun ../bin/xspec.sh "catalog/catalog-01_xspec-uri.xspec"
[ "$status" -eq 0 ]
[ "${lines[18]}" = "passed: 5 / pending: 0 / failed: 0 / total: 5" ]
}

@test "$x:xspec-uri with file imported via XML Catalog (XQuery)" {
export SAXON_CP="${SAXON_CP}:${APACHE_XMLRESOLVER_JAR}"
export XML_CATALOG="catalog/01/catalog-rewriteURI.xml"

myrun ../bin/xspec.sh -q "catalog/catalog-01_xspec-uri.xspec"
[ "$status" -eq 0 ]
[ "${lines[8]}" = "passed: 5 / pending: 0 / failed: 0 / total: 5" ]
}

@test "$x:xspec-uri with file imported via XML Catalog (Schematron)" {
export SAXON_CP="${SAXON_CP}:${APACHE_XMLRESOLVER_JAR}"
export XML_CATALOG="catalog/01/catalog-rewriteURI.xml"

myrun ../bin/xspec.sh -s "catalog/catalog-01_xspec-uri.xspec"
[ "$status" -eq 0 ]
[ "${lines[23]}" = "passed: 5 / pending: 0 / failed: 0 / total: 5" ]
}

#
# SAXON_HOME (CLI)
#
Expand Down

0 comments on commit ecad57a

Please sign in to comment.