New tests for "castable" applied to user-defined list and union types
authorMichael Kay <mike@saxonica.com>
Wed, 27 Jun 2018 13:10:37 +0100
changeset 1860 1a492368c675
parent 1859 7252da809ea9
child 1861 c33673636f1c
New tests for "castable" applied to user-defined list and union types
tests/expr/castable/_castable-test-set.xml
tests/expr/castable/castable-005.xsl
tests/expr/castable/castable-006.xsl
tests/expr/castable/unionListDefined.xsd
--- a/tests/expr/castable/_castable-test-set.xml	Wed Jun 27 13:09:41 2018 +0100
+++ b/tests/expr/castable/_castable-test-set.xml	Wed Jun 27 13:10:37 2018 +0100
@@ -68,4 +68,36 @@
          <assert-xml><![CDATA[<out xmlns:xs="http://www.w3.org/2001/XMLSchema"><a>true</a><a>true</a><a>true</a><a>true</a><b>false</b><b>false</b><b>false</b><b>false</b></out>]]></assert-xml>
       </result>
    </test-case>
+   
+   <test-case name="castable-005">
+      <description>Test "castable as" operator applied to schema-defined union types (conversion of QT3 tests)</description>
+      <created by="Michael Kay" on="2018-06-16"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+         <feature value="schema_aware"/>
+         <feature value="higher_order_functions"/>
+      </dependencies>
+      <test>
+         <stylesheet file="castable-005.xsl"/>
+      </test>
+      <result>
+         <assert>empty(/out/failure)</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="castable-006">
+      <description>Test "castable as" operator applied to schema-defined list types (conversion of QT3 tests)</description>
+      <created by="Michael Kay" on="2018-06-16"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+         <feature value="schema_aware"/>
+         <feature value="higher_order_functions"/>
+      </dependencies>
+      <test>
+         <stylesheet file="castable-006.xsl"/>
+      </test>
+      <result>
+         <assert>empty(/out/failure)</assert>
+      </result>
+   </test-case>
 </test-set>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/expr/castable/castable-005.xsl	Wed Jun 27 13:10:37 2018 +0100
@@ -0,0 +1,515 @@
+<?xml version="1.0" ?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
+    version="3.0"
+    xmlns:s="http://www.w3.org/XQueryTest/unionListDefined"
+    exclude-result-prefixes="#all">
+    
+    <!-- castable operator with union types. Tests created by manual conversion of QT3 tests Castable-UnionType-* -->
+
+    <xsl:import-schema namespace="http://www.w3.org/XQueryTest/unionListDefined" schema-location="unionListDefined.xsd"/>
+    
+    <xsl:function name="s:lazy">
+        <xsl:param name="p"/>
+        <xsl:sequence select="if (current-date() gt xs:date('1900-01-01')) then $p else '*!*!*!*'"/>
+    </xsl:function>
+
+    <xsl:variable name="qt3tests">
+        <test-case name="Castable-UnionType-1" covers-30="cast-to-union">
+            <description>Test the union type that should return an xs:integer value</description>
+            <created by="O'Neil Delpratt" on="2011-10-27"/>
+            <modified by="Michael Kay" on="2015-01-06" change="drop version declaration from query"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      "123" castable as s:myUnionType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy("123") castable as s:myUnionType1'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-2" covers-30="cast-to-union">
+            <description>Test castability of xs:string to union type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      "2001-01-01" castable as s:myUnionType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy("2001-01-01") castable as s:myUnionType1'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-3" covers-30="cast-to-union">
+            <description>Test castability of xs:string to union type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      "string" castable as s:myUnionType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy("string") castable as s:myUnionType1'/></test2>
+            <result>
+                <assert-false/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-4" covers-30="cast-to-union">
+            <description>Test castability of xs:untypedAtomic to union type.</description>
+            <created by="O'Neil Delpratt" on="2011-10-27"/>
+            <modified by="Michael Kay" on="2015-01-06" change="drop version declaration from query"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      xs:untypedAtomic("123") castable as s:myUnionType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(xs:untypedAtomic("123")) castable as s:myUnionType1'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-5" covers-30="cast-to-union">
+            <description>Test castability of xs:untypedAtomic to union type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      xs:untypedAtomic("2001-01-01") castable as s:myUnionType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(xs:untypedAtomic("2001-01-01")) castable as s:myUnionType1'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-6" covers-30="cast-to-union">
+            <description>Test castability of xs:untypedAtomic to union type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      xs:untypedAtomic("string") castable as s:myUnionType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(xs:untypedAtomic("string")) castable as s:myUnionType1'/></test2>           
+            <result>
+                <assert-false/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-7" covers-30="cast-to-union">
+            <description>Test castability of a value that is an instance of one of the atomic types
+                in the transitive membership of the union type</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      s:unrestrictedInteger(123) castable as s:myUnionType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(s:unrestrictedInteger(123)) castable as s:myUnionType1'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-8" covers-30="cast-to-union">
+            <description>Test castability of a value that is an instance of one of the atomic types
+                in the transitive membership of the union type</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      s:unrestrictedDate("2001-01-01") castable as s:myUnionType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(s:unrestrictedDate("2001-01-01")) castable as s:myUnionType1'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-9" covers-30="cast-to-union">
+            <description>Test castability of a value that is not an instance of one of the atomic
+                types in the transitive membership of the union type</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      xs:gYear("2001") castable as s:myUnionType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(xs:gYear("2001")) castable as s:myUnionType1'/></test2>
+            <result>
+                <assert-false/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-10" covers-30="cast-to-union">
+            <description>Test castability of a value that is an instance of the union type
+                itself</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      s:myUnionType1("2001-01-01") castable as s:myUnionType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(s:myUnionType1("2001-01-01")) castable as s:myUnionType1'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-11" covers-30="cast-to-union">
+            <description>Test castability of a value that is an instance of one of the atomic types
+                in the transitive membership of the union type</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      xs:integer(123) castable as s:myUnionType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(xs:integer(123)) castable as s:myUnionType1'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-12" covers-30="cast-to-union">
+            <description>Test castability of a value that is castable to one or more of the atomic
+                types in the transitive membership of the union type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      xs:date("2001-01-01") castable as s:myUnionType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(xs:date("2001-01-01")) castable as s:myUnionType1'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-13" covers-30="cast-to-union">
+            <description>Test castability of empty sequence to a union type</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      () castable as s:myUnionType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(()) castable as s:myUnionType1'/></test2>
+            <result>
+                <assert-false/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-14" covers-30="cast-to-union">
+            <description>Test the union type that should return an xs:integer value</description>
+            <created by="O'Neil Delpratt" on="2011-10-27"/>
+            <modified by="Michael Kay" on="2015-01-06" change="drop version declaration from query"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      "123" castable as s:myUnionType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy("123") castable as s:myUnionType1?'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-15" covers-30="cast-to-union">
+            <description>Test castability of xs:string to union type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      "2001-01-01" castable as s:myUnionType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy("2001-01-01") castable as s:myUnionType1?'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-16" covers-30="cast-to-union">
+            <description>Test castability of xs:string to union type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      "string" castable as s:myUnionType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy("string") castable as s:myUnionType1?'/></test2>
+            <result>
+                <assert-false/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-17" covers-30="cast-to-union">
+            <description>Test castability of xs:untypedAtomic to union type.</description>
+            <created by="O'Neil Delpratt" on="2011-10-27"/>
+            <modified by="Michael Kay" on="2015-01-06" change="drop version declaration from query"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      xs:untypedAtomic("123") castable as s:myUnionType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(xs:untypedAtomic("123")) castable as s:myUnionType1?'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-18" covers-30="cast-to-union">
+            <description>Test castability of xs:untypedAtomic to union type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      xs:untypedAtomic("2001-01-01") castable as s:myUnionType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(xs:untypedAtomic("123")) castable as s:myUnionType1?'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-19" covers-30="cast-to-union">
+            <description>Test castability of xs:untypedAtomic to union type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      xs:untypedAtomic("string") castable as s:myUnionType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(xs:untypedAtomic("string")) castable as s:myUnionType1?'/></test2>
+            <result>
+                <assert-false/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-20" covers-30="cast-to-union">
+            <description>Test castability of a value that is an instance of one of the atomic types
+                in the transitive membership of the union type</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      s:unrestrictedInteger(123) castable as s:myUnionType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(s:unrestrictedInteger(123)) castable as s:myUnionType1?'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-21" covers-30="cast-to-union">
+            <description>Test castability of a value that is an instance of one of the atomic types
+                in the transitive membership of the union type</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      s:unrestrictedDate("2001-01-01") castable as s:myUnionType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(s:unrestrictedDate("2001-01-01")) castable as s:myUnionType1?'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-22" covers-30="cast-to-union">
+            <description>Test castability of a value that is not an instance of one of the atomic
+                types in the transitive membership of the union type</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      xs:gYear("2001") castable as s:myUnionType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(xs:gYear("2001")) castable as s:myUnionType1?'/></test2>
+            <result>
+                <assert-false/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-23" covers-30="cast-to-union">
+            <description>Test castability of a value that is an instance of the union type
+                itself</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      s:myUnionType1("2001-01-01") castable as s:myUnionType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(s:myUnionType1("2001-01-01")) castable as s:myUnionType1?'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-24" covers-30="cast-to-union">
+            <description>Test castability of a value that is an instance of one of the atomic types
+                in the transitive membership of the union type</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      xs:integer(123) castable as s:myUnionType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(xs:integer(123)) castable as s:myUnionType1?'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-25" covers-30="cast-to-union">
+            <description>Test castability of a value that is castable to one or more of the atomic
+                types in the transitive membership of the union type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      xs:date("2001-01-01") castable as s:myUnionType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(xs:date("2001-01-01")) castable as s:myUnionType1?'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-26" covers-30="cast-to-union">
+            <description>Test castability of empty sequence to a union type</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+      () castable as s:myUnionType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(()) castable as s:myUnionType1?'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+
+
+        <test-case name="Castable-UnionType-36" covers-30="type-derivation-with-unions">
+            <description>Castable from a union type to string</description>
+            <created by="Michael Kay" on="2014-05-04"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+         import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+         declare function local:f($a as s:dateOrDateTime) as xs:boolean { $a castable as xs:string };
+         local:f(xs:date('2001-01-01'))
+       ]]></test>
+            <test2><xsl:value-of select='let $f := function ($a as s:dateOrDateTime) as xs:boolean { $a castable as xs:string }
+                return $f(s:lazy(xs:date("2001-01-01")))'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-37" covers-30="type-derivation-with-unions">
+            <description>Castable from a union type to one of the member types</description>
+            <created by="Michael Kay" on="2014-05-04"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+         import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+         declare function local:f($a as s:dateOrDateTime) as xs:boolean { $a castable as xs:dateTime };
+         local:f(xs:date('2001-01-01'))
+       ]]></test>
+            <test2><xsl:value-of select='let $f := function($a as s:dateOrDateTime) as xs:boolean { $a castable as xs:dateTime }
+                return $f(s:lazy(xs:date("2001-01-01")))'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-UnionType-38" covers-30="type-derivation-with-unions">
+            <description>Castable from a union type to one of the member types</description>
+            <created by="Michael Kay" on="2014-05-04"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+         import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+         declare function local:f($a as s:dateOrDateTime) as xs:boolean { $a castable as xs:date };
+         local:f(xs:date('2001-01-01'))
+       ]]></test>
+            <test2><xsl:value-of select='let $f := function ($a as s:dateOrDateTime) as xs:boolean { $a castable as xs:date }
+                return $f(s:lazy(xs:date("2001-01-01")))'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+    </xsl:variable>
+    
+    <xsl:template name="xsl:initial-template">
+        <out>
+            <xsl:for-each select="$qt3tests/test-case[(result/assert-true and not(test2 = 'true')) or (result/assert-false and not(test2 = 'false'))]">
+                <failure test="{@name}"/>
+            </xsl:for-each>
+        </out>
+    </xsl:template>
+
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/expr/castable/castable-006.xsl	Wed Jun 27 13:10:37 2018 +0100
@@ -0,0 +1,325 @@
+<?xml version="1.0" ?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema" version="3.0"
+    xmlns:s="http://www.w3.org/XQueryTest/unionListDefined" exclude-result-prefixes="#all">
+
+    <!-- castable operator with list types. Tests created by manual conversion of QT3 tests Castable-ListType-* -->
+
+    <xsl:import-schema namespace="http://www.w3.org/XQueryTest/unionListDefined"
+        schema-location="unionListDefined.xsd"/>
+
+    <xsl:function name="s:lazy">
+        <xsl:param name="p"/>
+        <xsl:sequence
+            select="
+                if (current-date() gt xs:date('1900-01-01')) then
+                    $p
+                else
+                    '*!*!*!*'"
+        />
+    </xsl:function>
+
+    <xsl:variable name="qt3tests">
+        <test-case name="Castable-ListType-2" covers-30="cast-to-list">
+            <description>Cast the expression to the defined list type. The test should fail as the
+                base type for the list is decimal</description>
+            <created by="O'Neil Delpratt" on="2011-10-27"/>
+            <modified by="Michael Kay" on="2015-01-06" change="drop version declaration from query"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+        "1.1 2.1 3.1" castable as s:intListType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy("1.1 2.1 3.1") castable as s:intListType1'/></test2>
+            <result>
+                <assert-false/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-ListType-3" covers-30="cast-to-list">
+            <description>Test castability of xs:string to list type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+        "1 2 3" castable as s:intListType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy("1 2 3") castable as s:intListType1'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-ListType-4" covers-30="cast-to-list">
+            <description>Test castability of xs:string to list type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+        "" castable as s:intListType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy("") castable as s:intListType1'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-ListType-5" covers-30="cast-to-list">
+            <description>Test castability of xs:untypedAtomic to list type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+        xs:untypedAtomic("1.1 2.1 3.1") castable as s:intListType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(xs:untypedAtomic("1.1 2.1 3.1")) castable as s:intListType1'/></test2>
+            <result>
+                <assert-false/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-ListType-6" covers-30="cast-to-list">
+            <description>Test castability of xs:untypedAtomic to list type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+        xs:untypedAtomic("1 2 3") castable as s:intListType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(xs:untypedAtomic("1 2 3")) castable as s:intListType1'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-ListType-7" covers-30="cast-to-list">
+            <description>Test castability of xs:untypedAtomic to list type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+        xs:untypedAtomic("") castable as s:intListType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(xs:untypedAtomic("")) castable as s:intListType1'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-ListType-8" covers-30="cast-to-list">
+            <description>Test castability of xs:integer sequence to list type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+        (1, 2, 3) castable as s:intListType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy((1, 2, 3)) castable as s:intListType1'/></test2>
+            <result>
+                <assert-false/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-ListType-9" covers-30="cast-to-list">
+            <description>Test castability of empty sequence to list type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <modified by="Tim Mills" on="2016-04-25" change="see bugs 29571, 29584"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+        () castable as s:intListType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(()) castable as s:intListType1'/></test2>
+            <result>
+                <assert-false/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-ListType-10" covers-30="cast-to-list">
+            <description>Test castability of s:intListType1 sequence to list type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+        s:intListType1("1 2 3") castable as s:intListType1]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(s:intListType1("1 2 3")) castable as s:intListType1'/></test2>
+            <result>
+                <assert-false/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-ListType-11" covers-30="cast-to-list">
+            <description>Test castability of xs:string to list type. The test should fail as the
+                base type for the list is decimal</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+        "1.1 2.1 3.1" castable as s:intListType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy("1.1 2.1 3.1") castable as s:intListType1?'/></test2>
+            <result>
+                <assert-false/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-ListType-12" covers-30="cast-to-list">
+            <description>Test castability of xs:string to list type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+        "1 2 3" castable as s:intListType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy("1 2 3") castable as s:intListType1?'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-ListType-13" covers-30="cast-to-list">
+            <description>Test castability of xs:string to list type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+        "" castable as s:intListType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy("") castable as s:intListType1?'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-ListType-14" covers-30="cast-to-list">
+            <description>Test castability of xs:untypedAtomic to list type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+        xs:untypedAtomic("1.1 2.1 3.1") castable as s:intListType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(xs:untypedAtomic("1.1 2.1 3.1")) castable as s:intListType1?'/></test2>
+            <result>
+                <assert-false/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-ListType-15" covers-30="cast-to-list">
+            <description>Test castability of xs:untypedAtomic to list type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+        xs:untypedAtomic("1 2 3") castable as s:intListType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(xs:untypedAtomic("1 2 3")) castable as s:intListType1?'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-ListType-16" covers-30="cast-to-list">
+            <description>Test castability of xs:untypedAtomic to list type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+        xs:untypedAtomic("") castable as s:intListType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(xs:untypedAtomic("")) castable as s:intListType1?'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-ListType-17" covers-30="cast-to-list">
+            <description>Test castability of xs:integer sequence to list type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+        (1, 2, 3) castable as s:intListType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy((1, 2, 3)) castable as s:intListType1?'/></test2>
+            <result>
+                <assert-false/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-ListType-18" covers-30="cast-to-list">
+            <description>Test castability of empty sequence to list type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+        () castable as s:intListType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(()) castable as s:intListType1?'/></test2>
+            <result>
+                <assert-true/>
+            </result>
+        </test-case>
+
+        <test-case name="Castable-ListType-19" covers-30="cast-to-list">
+            <description>Test castability of s:intListType1 sequence to list type.</description>
+            <created by="Tim Mills" on="2016-04-11"/>
+            <environment ref="union-List-defined-Types"/>
+            <dependency type="spec" value="XQ30+"/>
+            <dependency type="feature" value="schemaImport"/>
+            <test><![CDATA[
+       import schema namespace s="http://www.w3.org/XQueryTest/unionListDefined";
+        s:intListType1("1 2 3") castable as s:intListType1?]]>
+            </test>
+            <test2><xsl:value-of select='s:lazy(s:intListType1("1 2 3")) castable as s:intListType1?'/></test2>
+            <result>
+                <assert-false/>
+            </result>
+        </test-case>
+    </xsl:variable>
+
+    <xsl:template name="xsl:initial-template">
+        <out>
+            <xsl:for-each
+                select="$qt3tests/test-case[(result/assert-true and not(test2 = 'true')) or (result/assert-false and not(test2 = 'false'))]">
+                <failure test="{@name}"/>
+            </xsl:for-each>
+        </out>
+    </xsl:template>
+
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/expr/castable/unionListDefined.xsd	Wed Jun 27 13:10:37 2018 +0100
@@ -0,0 +1,126 @@
+<?xml version="1.0" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+           xmlns:s="http://www.w3.org/XQueryTest/unionListDefined"
+           targetNamespace="http://www.w3.org/XQueryTest/unionListDefined"
+           elementFormDefault="qualified">
+
+  <xs:simpleType name="unrestrictedInteger">
+    <xs:restriction base='xs:integer'/>
+  </xs:simpleType> 
+  
+  <xs:simpleType name="unrestrictedDate">
+    <xs:restriction base='xs:date'/>
+  </xs:simpleType>  
+  
+  <xs:simpleType name='myUnionType1'>
+    <xs:union memberTypes="s:unrestrictedInteger s:unrestrictedDate"/>
+  </xs:simpleType>
+  
+  <xs:simpleType name="restrictedString">
+    <xs:restriction base='xs:string'>
+      <xs:pattern value='IB(\d)+'/>
+    </xs:restriction>
+  </xs:simpleType>  
+
+  <xs:simpleType name='myUnionType2'>
+    <xs:union memberTypes="s:restrictedString s:unrestrictedInteger"/>
+  </xs:simpleType>
+  
+  <xs:simpleType name="sensitiveUnion">
+    <xs:union memberTypes="xs:NCName xs:QName"/>
+  </xs:simpleType>
+
+  <xs:simpleType name='decimalListType1'>
+    <xs:list itemType='xs:decimal'/>
+  </xs:simpleType>
+
+  <xs:simpleType name='impureUnionType'>
+    <xs:union memberTypes="xs:date s:decimalListType1"/>
+  </xs:simpleType>
+
+  <xs:simpleType name='strListType1'>
+    <xs:list itemType='xs:string'/>
+  </xs:simpleType>
+
+  <xs:simpleType name='intListType1'>
+	<xs:list itemType='xs:integer'/>
+  </xs:simpleType>
+
+  <xs:simpleType name='myRestrictedList1'>
+	<xs:restriction base='s:intListType1'>
+		<xs:pattern value='123 (\d+\s)*456'/>
+	</xs:restriction>
+  </xs:simpleType>
+  
+  <xs:simpleType name="sensitiveList">
+    <xs:list itemType="s:sensitiveUnion"/>
+  </xs:simpleType>
+  
+  <xs:simpleType name="lowercaseName">
+    <xs:restriction base="s:sensitiveUnion">
+      <xs:pattern value="[a-z:]+"/>
+    </xs:restriction>
+  </xs:simpleType>
+  
+  <xs:simpleType name="unionOfLists">
+    <xs:union memberTypes="xs:IDREFS s:sensitiveList"/>
+  </xs:simpleType>
+  
+  <xs:simpleType name="unionOfListsAndAtomic">
+    <xs:union memberTypes="xs:integer xs:NMTOKENS "/>
+  </xs:simpleType>
+  
+  <xs:simpleType name="listOfUnions">
+    <xs:list itemType="s:sensitiveUnion"/>
+  </xs:simpleType>
+  
+  <xs:simpleType name="approximateDate">
+    <xs:union memberTypes="xs:date xs:dateTime xs:gYear xs:gYearMonth"/>
+  </xs:simpleType>
+  
+  <xs:simpleType name="dateOrDateTime">
+    <xs:union memberTypes="xs:date xs:dateTime"/>
+  </xs:simpleType>  
+  
+  <xs:simpleType name="restrictedUnion">
+    <xs:restriction base="s:approximateDate">      
+      <xs:pattern value="20.*"/>
+    </xs:restriction>  
+  </xs:simpleType>
+  
+  <xs:simpleType name="restrictedDate">
+    <xs:restriction base="s:unrestrictedDate">      
+      <xs:pattern value="20.*"/>
+    </xs:restriction>  
+  </xs:simpleType>
+  
+  <xs:element name="elementContainingApproximateDate" type="s:elementContainingApproximateDateType"/>
+  
+    <xs:complexType name="elementContainingApproximateDateType">
+      <xs:sequence>
+        <xs:element name="e" type="s:approximateDate"/>
+      </xs:sequence>
+    </xs:complexType>  
+  
+  <xs:element name="elementContainingDateTime" substitutionGroup="s:elementContainingApproximateDate"
+            type="s:elementContainingDateType"/>
+    
+  <xs:complexType name="elementContainingDateType">
+    <xs:complexContent>
+      <xs:restriction base="s:elementContainingApproximateDateType">
+        <xs:sequence>
+          <xs:element name="e" type="xs:dateTime"/>
+        </xs:sequence>
+      </xs:restriction>
+    </xs:complexContent>    
+  </xs:complexType>    
+
+  <xs:simpleType name="decimal-or-string">
+    <xs:union memberTypes="xs:decimal xs:string"/>
+  </xs:simpleType>
+
+  <xs:simpleType name="integer-union">
+    <xs:union memberTypes="xs:nonPositiveInteger xs:nonNegativeInteger"/>
+  </xs:simpleType>
+
+</xs:schema>