Skip to content

Commit

Permalink
Report all the basic types and valid numeric expressions (#58)
Browse files Browse the repository at this point in the history
- Cover all the built-in types supported by every XSLT 2.0 processor #50 
- Fix test:report-atomic-value() for numeric literals #55
  • Loading branch information
AirQuick authored and Sandro Cirulli committed Jan 19, 2017
1 parent f2db6e4 commit 9b94529
Show file tree
Hide file tree
Showing 4 changed files with 453 additions and 5 deletions.
57 changes: 52 additions & 5 deletions src/compiler/generate-tests-utils.xsl
Expand Up @@ -634,11 +634,25 @@
replace($value, '''', ''''''),
'''')" />
</xsl:when>
<xsl:when test="$value instance of xs:integer or
$value instance of xs:decimal or
$value instance of xs:double">

<!-- Numeric literals: http://www.w3.org/TR/xpath20/#id-literals -->
<!-- Check integer before decimal, because of derivation -->
<xsl:when test="$value instance of xs:integer">
<xsl:value-of select="$value" />
</xsl:when>
<xsl:when test="$value instance of xs:decimal">
<xsl:value-of>
<xsl:variable as="xs:string" name="decimal-string" select="string($value)"/>
<xsl:sequence select="$decimal-string"/>
<xsl:sequence select="'.0'[not(contains($decimal-string,'.'))]"/>
</xsl:value-of>
</xsl:when>
<!-- xs:double
Just defer it to xsl:otherwise. Justifications below.
- Expression is a bit complicated: http://www.w3.org/TR/xpath-functions/#casting-to-string
- Not used as frequently as integer
- xsl:otherwise will return valid expression. It's just some more verbose than numeric literal. -->

<xsl:when test="$value instance of xs:QName">
<xsl:value-of
select="concat('QName(''', namespace-uri-from-QName($value),
Expand All @@ -658,13 +672,46 @@
<xsl:function name="test:atom-type" as="xs:string">
<xsl:param name="value" as="xs:anyAtomicType" />
<xsl:choose>
<!-- Grouped as the spec does.
Groups are in the reversed order so that the derived types are before the primitive types,
otherwise xs:integer is recognised as xs:decimal, xs:yearMonthDuration as xs:duration, and so on. -->

<!-- http://www.w3.org/TR/xslt20/#built-in-types
Every XSLT 2.0 processor includes the following named type definitions in the in-scope schema components: -->

<!-- * The following types defined in [XPath 2.0] -->
<xsl:when test="$value instance of xs:yearMonthDuration">xs:yearMonthDuration</xsl:when>
<xsl:when test="$value instance of xs:dayTimeDuration">xs:dayTimeDuration</xsl:when>
<!-- xs:anyAtomicType: Abstract -->
<!-- xs:untyped: Not atomic -->
<xsl:when test="$value instance of xs:untypedAtomic">xs:untypedAtomic</xsl:when>

<!-- * The types xs:anyType and xs:anySimpleType. -->
<!-- Not atomic -->

<!-- * The derived atomic type xs:integer defined in [XML Schema Part 2]. -->
<xsl:when test="$value instance of xs:integer">xs:integer</xsl:when>

<!-- * All the primitive atomic types defined in [XML Schema Part 2], with the exception of xs:NOTATION. -->
<xsl:when test="$value instance of xs:string">xs:string</xsl:when>
<xsl:when test="$value instance of xs:boolean">xs:boolean</xsl:when>
<xsl:when test="$value instance of xs:decimal">xs:decimal</xsl:when>
<xsl:when test="$value instance of xs:double">xs:double</xsl:when>
<xsl:when test="$value instance of xs:anyURI">xs:anyURI</xsl:when>
<xsl:when test="$value instance of xs:dateTime">xs:dateTime</xsl:when>
<xsl:when test="$value instance of xs:float">xs:float</xsl:when>
<xsl:when test="$value instance of xs:date">xs:date</xsl:when>
<xsl:when test="$value instance of xs:time">xs:time</xsl:when>
<xsl:when test="$value instance of xs:dateTime">xs:dateTime</xsl:when>
<xsl:when test="$value instance of xs:duration">xs:duration</xsl:when>
<xsl:when test="$value instance of xs:QName">xs:QName</xsl:when>
<xsl:when test="$value instance of xs:anyURI">xs:anyURI</xsl:when>
<xsl:when test="$value instance of xs:gDay">xs:gDay</xsl:when>
<xsl:when test="$value instance of xs:gMonthDay">xs:gMonthDay</xsl:when>
<xsl:when test="$value instance of xs:gMonth">xs:gMonth</xsl:when>
<xsl:when test="$value instance of xs:gYearMonth">xs:gYearMonth</xsl:when>
<xsl:when test="$value instance of xs:gYear">xs:gYear</xsl:when>
<xsl:when test="$value instance of xs:base64Binary">xs:base64Binary</xsl:when>
<xsl:when test="$value instance of xs:hexBinary">xs:hexBinary</xsl:when>

<xsl:otherwise>xs:anyAtomicType</xsl:otherwise>
</xsl:choose>
</xsl:function>
Expand Down

0 comments on commit 9b94529

Please sign in to comment.