Some basic tests for load-xquery-module
authorMichael Kay <mike@saxonica.com>
Thu, 17 Aug 2017 17:50:52 +0100
changeset 1746 eceb96fa621d
parent 1744 60ad316ccf04
child 1747 eaccea174847
Some basic tests for load-xquery-module
catalog.xml
tests/decl/function/function-5006.xsl
tests/fn/load-xquery-module/_load-xquery-module-test-set.xml
tests/fn/load-xquery-module/load-xquery-module-001.xsl
tests/fn/load-xquery-module/load-xquery-module-002.xsl
tests/fn/load-xquery-module/load-xquery-module-003.xsl
tests/fn/load-xquery-module/load-xquery-module-004.xsl
tests/fn/load-xquery-module/valid-module.xqm
--- a/catalog.xml	Thu Aug 17 10:13:04 2017 +0100
+++ b/catalog.xml	Thu Aug 17 17:50:52 2017 +0100
@@ -85,6 +85,7 @@
       <test-set name="innermost" file="tests/fn/innermost/_innermost-test-set.xml"/>
       <test-set name="json-to-xml" file="tests/fn/json-to-xml/_json-to-xml-test-set.xml"/>
       <test-set name="key" file="tests/fn/key/_key-test-set.xml"/>
+      <test-set name="load-xquery-module" file="tests/fn/load-xquery-module/_load-xquery-module-test-set.xml"/>
       <test-set name="normalize-unicode" file="tests/fn/normalize-unicode/_normalize-unicode-test-set.xml"/> 
       <test-set name="outermost" file="tests/fn/outermost/_outermost-test-set.xml"/>
       <test-set name="position" file="tests/fn/position/_position-test-set.xml"/>
--- a/tests/decl/function/function-5006.xsl	Thu Aug 17 10:13:04 2017 +0100
+++ b/tests/decl/function/function-5006.xsl	Thu Aug 17 17:50:52 2017 +0100
@@ -18,6 +18,9 @@
     
     <xsl:function name="sf:deep-descent"  as="node()*" streamability="deep-descent">
         <xsl:param name="node" as="node()"/>
+        <!-- Written this way to circumvent a bug in the streamability rules: $node//section/p is not a scanning expression,
+            because when considered as a pattern it is not motionless, because a pattern that contains a rooted path (like $node)
+            is deemed not to be motionless. See bug 30064. -->
         <xsl:for-each select="$node">
             <xsl:sequence select="self::node()//section//p" />    
         </xsl:for-each>        
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/load-xquery-module/_load-xquery-module-test-set.xml	Thu Aug 17 17:50:52 2017 +0100
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test-set xmlns="http://www.w3.org/2012/10/xslt-test-catalog" xmlns:xs="http://www.w3.org/2001/XMLSchema" name="load-xquery-module">
+   <description>Tests load-xquery-module() function in XSLT 3.0</description>
+   
+   <environment name="load-xquery-module-A">
+         <resource uri="http://www.w3.org/fots/fn/load-xquery-module/valid/module"
+            file="valid-module.xqm"
+            media-type="application/xquery"/>
+   </environment>
+   
+   <dependencies>
+      <spec value="XSLT30+"/>
+      <feature value="XPath_3.1"/>
+      <feature value="higher_order_functions"/>
+   </dependencies>
+
+   <test-case name="load-xquery-module-001">
+      <description>Returns error, module is not available (non-existent file)</description>
+      <created by="Michael Kay" on="2017-08-17"/>
+      <environment ref="load-xquery-module-A"/>           
+      <test>
+         <stylesheet file="load-xquery-module-001.xsl"/>
+      </test>
+      <result>
+         <error code="XQST0059"/>
+      </result>
+   </test-case>
+   
+   <test-case name="load-xquery-module-002">
+      <description>Read value of a global variable from query module</description>
+      <created by="Michael Kay" on="2017-08-17"/>
+      <environment ref="load-xquery-module-A"/>           
+      <test>
+         <stylesheet file="load-xquery-module-002.xsl"/>
+      </test>
+      <result>
+         <assert>/out = "var1"</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="load-xquery-module-003">
+      <description>Invoke a function from query module</description>
+      <created by="Michael Kay" on="2017-08-17"/>
+      <environment ref="load-xquery-module-A"/>           
+      <test>
+         <stylesheet file="load-xquery-module-003.xsl"/>
+      </test>
+      <result>
+         <assert>/out = "func1"</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="load-xquery-module-004">
+      <description>Bind statically to a function from query module</description>
+      <created by="Michael Kay" on="2017-08-17"/>
+      <environment ref="load-xquery-module-A"/>           
+      <test>
+         <stylesheet file="load-xquery-module-004.xsl"/>
+      </test>
+      <result>
+         <assert>/out = "func1"</assert>
+      </result>
+   </test-case>
+ 
+
+
+
+</test-set>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/load-xquery-module/load-xquery-module-001.xsl	Thu Aug 17 17:50:52 2017 +0100
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:package xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:f="http://accum001/"
+  exclude-result-prefixes="xs f" version="3.0"  declared-modes="no" expand-text="yes">
+ 
+  <xsl:template name="xsl:initial-template">
+    <xsl:variable name="module" select="load-xquery-module('unknown-query')"/>
+    <xsl:sequence select="$module?variables(xs:QName('magic'))"/>
+  </xsl:template>
+  
+
+</xsl:package>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/load-xquery-module/load-xquery-module-002.xsl	Thu Aug 17 17:50:52 2017 +0100
@@ -0,0 +1,15 @@
+<xsl:package xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+   xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:f="http://accum001/"
+   exclude-result-prefixes="xs f" version="3.0"  declared-modes="no" expand-text="yes">
+   
+   <xsl:variable name="module-uri" select="'http://www.w3.org/fots/fn/load-xquery-module/valid/module'"/>
+   
+   <xsl:template name="xsl:initial-template">
+      <out>
+         <xsl:variable name="module" select="load-xquery-module($module-uri)"/>
+         <xsl:sequence select="$module?variables(QName($module-uri, 'var1'))"/>
+      </out>
+   </xsl:template>
+   
+   
+</xsl:package>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/load-xquery-module/load-xquery-module-003.xsl	Thu Aug 17 17:50:52 2017 +0100
@@ -0,0 +1,15 @@
+<xsl:package xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+   xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:f="http://accum001/"
+   exclude-result-prefixes="xs f" version="3.0"  declared-modes="no" expand-text="yes">
+   
+   <xsl:variable name="module-uri" select="'http://www.w3.org/fots/fn/load-xquery-module/valid/module'"/>
+   
+   <xsl:template name="xsl:initial-template">
+      <out>
+         <xsl:variable name="module" select="load-xquery-module($module-uri)"/>
+         <xsl:sequence select="$module?functions(QName($module-uri, 'func1'))?0()"/>
+      </out>
+   </xsl:template>
+   
+   
+</xsl:package>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/load-xquery-module/load-xquery-module-004.xsl	Thu Aug 17 17:50:52 2017 +0100
@@ -0,0 +1,18 @@
+<xsl:package xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+   xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:f="http://accum001/"
+   exclude-result-prefixes="xs f" version="3.0"  declared-modes="no" expand-text="yes">
+   
+   <!-- Bind statically to a function in a query module -->
+   
+   <xsl:variable name="module-uri" select="'http://www.w3.org/fots/fn/load-xquery-module/valid/module'" static="yes"/>
+   <xsl:variable name="module" select="load-xquery-module($module-uri)" static="yes"/>
+   <xsl:variable name="fun" select="$module?functions(QName($module-uri, 'func1'))?0" static="yes"/>
+   
+   <xsl:template name="xsl:initial-template">
+      <out use-when="$fun instance of function(*)">        
+         <xsl:sequence select="$fun()"/>
+      </out>
+   </xsl:template>
+   
+   
+</xsl:package>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/load-xquery-module/valid-module.xqm	Thu Aug 17 17:50:52 2017 +0100
@@ -0,0 +1,14 @@
+xquery version "3.1";
+
+module namespace vm = "http://www.w3.org/fots/fn/load-xquery-module/valid/module";
+
+declare variable $vm:var1 := "var1";
+declare variable $vm:var2 := "var2";
+
+declare function vm:func1() {
+    "func1"
+};
+
+declare function vm:func2() {
+    "func2"
+};
\ No newline at end of file