Skip to content

Commit

Permalink
Fix #308 (x:label affects expectation) for XQuery (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
AirQuick committed Apr 11, 2019
1 parent b6e381c commit 2cf339d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
20 changes: 20 additions & 0 deletions src/compiler/generate-common-tests.xsl
Expand Up @@ -568,6 +568,26 @@
</xsl:copy>
</xsl:template>

<!-- Generates variable declarations for x:expect -->
<xsl:template name="x:setup-expected" as="node()+">
<!--<xsl:context-item as="element(x:expect)" use="required" />-->

<xsl:param name="var" as="xs:string" required="yes" />

<!-- Remove x:label from x:expect -->
<xsl:variable name="expect" as="element(x:expect)">
<xsl:copy>
<xsl:sequence select="(attribute() | node()) except x:label" />
</xsl:copy>
</xsl:variable>

<!-- Generate <xsl:variable name="impl:expected"> (XSLT)
or "let $local:expected := ..." (XQuery) to represent the expected items -->
<xsl:apply-templates select="$expect" mode="test:generate-variable-declarations">
<xsl:with-param name="var" select="$var" />
</xsl:apply-templates>
</xsl:template>

<!-- Removes duplicate nodes from a sequence of nodes. (Removes a node if it appears
in a prior position of the sequence.)
This function does not sort nodes in document order.
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/generate-query-helper.xsl
Expand Up @@ -34,7 +34,7 @@
use="concat('match=', normalize-space(@match), '+',
'mode=', normalize-space(@mode))"/>

<xsl:template match="*" mode="test:generate-variable-declarations">
<xsl:template match="*" as="node()+" mode="test:generate-variable-declarations">
<xsl:param name="var" as="xs:string" required="yes"/>
<xsl:param name="global" as="xs:boolean" select="false()"/>
<xsl:choose>
Expand Down
9 changes: 3 additions & 6 deletions src/compiler/generate-query-tests.xsl
Expand Up @@ -291,13 +291,10 @@
</xsl:for-each>
<xsl:text>)&#10;{&#10;</xsl:text>
<xsl:if test="not($pending-p)">
<!--
let $local:expected :=
( ... )
-->
<xsl:apply-templates select="." mode="test:generate-variable-declarations">
<!-- Set up the $local:expected variable -->
<xsl:call-template name="x:setup-expected">
<xsl:with-param name="var" select="'local:expected'" />
</xsl:apply-templates>
</xsl:call-template>

<!--
let $local:test-result :=
Expand Down
19 changes: 3 additions & 16 deletions src/compiler/generate-xspec-tests.xsl
Expand Up @@ -317,7 +317,9 @@
<xsl:variable name="xslt-version" as="xs:decimal"
select="(ancestor-or-self::*[@xslt-version]/@xslt-version, 2.0)[1]" />
<!-- Set up the $impl:expected variable -->
<xsl:apply-templates select="." mode="x:setup-expected" />
<xsl:call-template name="x:setup-expected">
<xsl:with-param name="var" select="'impl:expected'" />
</xsl:call-template>

<!-- Flags for test:deep-equal() enclosed in ''. -->
<xsl:variable name="deep-equal-flags" as="xs:string"
Expand Down Expand Up @@ -461,21 +463,6 @@
</xsl:apply-templates>
</xsl:template>

<xsl:template match="x:expect" mode="x:setup-expected" as="element(xsl:variable)+">
<!-- Remove x:label from x:expect -->
<xsl:variable name="expect" as="element(x:expect)">
<xsl:copy>
<xsl:sequence select="@*" />
<xsl:sequence select="node() except x:label" />
</xsl:copy>
</xsl:variable>

<!-- Generate <xsl:variable name="impl:expected"> to represent the expected items -->
<xsl:apply-templates select="$expect" mode="test:generate-variable-declarations">
<xsl:with-param name="var" select="'impl:expected'" />
</xsl:apply-templates>
</xsl:template>

<xsl:template match="x:context | x:param" mode="x:report">
<xsl:element name="x:{local-name()}">
<xsl:apply-templates select="@*" mode="x:report" />
Expand Down
7 changes: 4 additions & 3 deletions test/xspec-308.xspec
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description stylesheet="do-nothing.xsl" xmlns:x="http://www.jenitennison.com/xslt/xspec">
<x:description query="x-urn:test:do-nothing" query-at="do-nothing.xquery"
stylesheet="do-nothing.xsl" xmlns:do-nothing="x-urn:test:do-nothing"
xmlns:x="http://www.jenitennison.com/xslt/xspec">
<x:scenario label="When $x:result is element(foo)">
<x:call function="exactly-one">
<x:param as="element(foo)">
Expand All @@ -17,8 +19,7 @@
</x:expect>
</x:scenario>

<x:scenario
label="mode=x:setup-expected in generate-xspec-tests.xsl does not affect @href document. So...">
<x:scenario label="x:setup-expected template does not affect @href document. So...">
<x:call function="exactly-one">
<x:param as="document-node(element(x:label))" href="xspec-308.xml" />
</x:call>
Expand Down

0 comments on commit 2cf339d

Please sign in to comment.