New tests for function-lookup in XSLT context
authorMichael Kay <mike@saxonica.com>
Wed, 25 Apr 2018 09:59:32 +0100
changeset 1841 7b1b1f77a2d8
parent 1840 f15c91c9fb6b
child 1842 30689b11f4c0
New tests for function-lookup in XSLT context
catalog.xml
tests/fn/function-lookup/_function-lookup-test-set.xml
tests/fn/function-lookup/function-lookup-001.xsl
tests/fn/function-lookup/function-lookup-002.xsl
tests/fn/function-lookup/function-lookup-003.xsl
tests/fn/function-lookup/function-lookup-004.xsl
tests/fn/function-lookup/function-lookup-004a.xsl
tests/fn/function-lookup/function-lookup-005.xsl
tests/fn/function-lookup/function-lookup-005a.xsl
tests/fn/function-lookup/function-lookup-006.xsl
tests/fn/function-lookup/function-lookup-007.xsl
--- a/catalog.xml	Tue Apr 24 17:13:30 2018 +0100
+++ b/catalog.xml	Wed Apr 25 09:59:32 2018 +0100
@@ -79,7 +79,8 @@
       <test-set name="format-date" file="tests/fn/format-date/_format-date-test-set.xml"/>
       <test-set name="format-date-en" file="tests/fn/format-date-en/_format-date-en-test-set.xml"/>
       <test-set name="format-number" file="tests/fn/format-number/_format-number-test-set.xml"/>
-      <test-set name="function-available" file="tests/fn/function-available/_function-available-test-set.xml"/>         
+      <test-set name="function-available" file="tests/fn/function-available/_function-available-test-set.xml"/>
+      <test-set name="function-lookup" file="tests/fn/function-lookup/_function-lookup-test-set.xml"/>
       <test-set name="id" file="tests/fn/id/_id-test-set.xml"/>
       <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"/>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/function-lookup/_function-lookup-test-set.xml	Wed Apr 25 09:59:32 2018 +0100
@@ -0,0 +1,133 @@
+<?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="function-lookup">
+   <description>Tests the function-lookup() function</description>
+
+   <dependencies>
+      <spec value="XSLT30+"/>
+      <feature value="higher_order_functions"/>
+   </dependencies>
+
+   <test-case name="function-lookup-001">
+      <description>test function-lookup() on stylesheet function</description>
+      <created by="Michael Kay" on="2018-04-24"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="function-lookup-001.xsl"/>
+      </test>
+      <result>
+         <assert>/out = '15'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="function-lookup-002">
+      <description>test function-lookup() on stylesheet function with visibility="private"</description>
+      <created by="Michael Kay" on="2018-04-24"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="function-lookup-002.xsl"/>
+      </test>
+      <result>
+         <assert>/out = '15'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="function-lookup-003">
+      <description>test function-lookup() in a static expression (fails)</description>
+      <created by="Michael Kay" on="2018-04-24"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="function-lookup-003.xsl"/>
+      </test>
+      <result>
+         <assert>not(/out/one)</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="function-lookup-004">
+      <description>function-lookup() can't see hidden functions</description>
+      <created by="Michael Kay" on="2018-04-24"/>
+      <environment>
+         <package file="function-lookup-004a.xsl" role="secondary" uri="http://function-lookup-004a/" package-version="1.0"/>
+      </environment>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <package file="function-lookup-004.xsl" role="principal"/>
+         <initial-template name="main"/>
+      </test>
+      <result>
+         <assert>/out = 'false'</assert>
+      </result>
+   </test-case>
+   
+   <test-case name="function-lookup-005">
+      <description>function-lookup() in used package</description>
+      <created by="Michael Kay" on="2018-04-24"/>
+      <environment>
+         <package file="function-lookup-005a.xsl" role="secondary" uri="http://function-lookup-005a/" package-version="1.0"/>
+      </environment>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <package file="function-lookup-005.xsl" role="principal"/>
+         <initial-template name="main"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>/out/sub/multiply/@exists = 'true'</assert>
+            <assert>/out/sub/divide/@exists = 'false'</assert>
+            <assert>/out/sub/add/@exists = 'true'</assert>
+            <assert>/out/sub/add/@effect = '7'</assert>
+            <assert>/out/sub/subtract/@exists = 'false'</assert>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="function-lookup-006">
+      <description>function-lookup(xsl:override)</description>
+      <created by="Michael Kay" on="2018-04-24"/>
+      <environment>
+         <package file="function-lookup-005a.xsl" role="secondary" uri="http://function-lookup-005a/" package-version="1.0"/>
+      </environment>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <package file="function-lookup-006.xsl" role="principal"/>
+         <initial-template name="main"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>/out/@result = '7'</assert>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="function-lookup-007">
+      <description>function-lookup with a context-sensitive system function</description>
+      <created by="Michael Kay" on="2018-04-24"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="function-lookup-007.xsl" role="principal"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>/out = 'pferd'</assert>
+         </all-of>
+      </result>
+   </test-case>
+   
+
+
+
+</test-set>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/function-lookup/function-lookup-001.xsl	Wed Apr 25 09:59:32 2018 +0100
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    exclude-result-prefixes="xs"
+    xmlns:f="http://local/"
+    version="3.0"
+    expand-text="yes">
+       
+    <xsl:template name="xsl:initial-template">
+        <out>{function-lookup(QName('http://local/', 'multiply'), 2)(3, 5)}</out>
+    </xsl:template>
+    
+    <xsl:function name="f:multiply">
+        <xsl:param name='x'/>
+        <xsl:param name="y"/>
+        <xsl:sequence select="$x * $y"/>
+    </xsl:function>
+
+</xsl:stylesheet>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/function-lookup/function-lookup-002.xsl	Wed Apr 25 09:59:32 2018 +0100
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    exclude-result-prefixes="xs"
+    xmlns:f="http://local/"
+    version="3.0"
+    expand-text="yes">
+       
+    <xsl:template name="xsl:initial-template">
+        <out>{function-lookup(QName('http://local/', 'multiply'), 2)(3, 5)}</out>
+    </xsl:template>
+    
+    <xsl:function name="f:multiply" visibility="private">
+        <xsl:param name='x'/>
+        <xsl:param name="y"/>
+        <xsl:sequence select="$x * $y"/>
+    </xsl:function>
+
+</xsl:stylesheet>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/function-lookup/function-lookup-003.xsl	Wed Apr 25 09:59:32 2018 +0100
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    exclude-result-prefixes="xs"
+    xmlns:f="http://local/"
+    version="3.0"
+    expand-text="yes">
+    
+ 
+    <xsl:template name="xsl:initial-template">
+        <out>
+            <one xsl:use-when="exists(function-lookup(QName('http://local/', 'multiply'), 2))">
+                <two/>
+            </one>
+        </out>
+    </xsl:template>
+    
+    <xsl:function name="f:multiply" visibility="private">
+        <xsl:param name='x'/>
+        <xsl:param name="y"/>
+        <xsl:sequence select="$x * $y"/>
+    </xsl:function>
+
+</xsl:stylesheet>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/function-lookup/function-lookup-004.xsl	Wed Apr 25 09:59:32 2018 +0100
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:package xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    name="http://function-lookup-004/"
+    package-version="1.0"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    exclude-result-prefixes="xs"
+    xmlns:f="http://local/"
+    version="3.0"
+    expand-text="yes">
+    
+    <xsl:use-package name="http://function-lookup-004a/"/>
+    
+ 
+    <xsl:template name="main" visibility="public">
+        <out>{exists(function-lookup(QName('http://local/', 'multiply'), 2))}</out>
+    </xsl:template>
+    
+
+</xsl:package>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/function-lookup/function-lookup-004a.xsl	Wed Apr 25 09:59:32 2018 +0100
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:package xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    name="http://function-lookup-004a/"
+    package-version="1.0"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    exclude-result-prefixes="xs"
+    xmlns:f="http://local/"
+    version="3.0"
+    expand-text="yes">
+ 
+    
+    <xsl:function name="f:multiply" visibility="private">
+        <xsl:param name='x'/>
+        <xsl:param name="y"/>
+        <xsl:sequence select="$x * $y"/>
+    </xsl:function>
+
+</xsl:package>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/function-lookup/function-lookup-005.xsl	Wed Apr 25 09:59:32 2018 +0100
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:package xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    name="http://function-lookup-005/"
+    package-version="1.0"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    exclude-result-prefixes="xs"
+    xmlns:f="http://local/"
+    version="3.0"
+    expand-text="yes">
+    
+    <xsl:use-package name="http://function-lookup-005a/">
+        <xsl:override>
+            <xsl:function name="f:add" visibility="public">
+                <xsl:param name='x'/>
+                <xsl:param name="y"/>
+                <xsl:sequence select="$x + $y + 1"/>
+            </xsl:function>
+            <xsl:function name="f:subtract" visibility="public">
+                <xsl:param name='x'/>
+                <xsl:param name="y"/>
+                <xsl:sequence select="$x + $y + 1"/>
+            </xsl:function>
+        </xsl:override>
+    </xsl:use-package>
+    
+ 
+    <xsl:template name="main" visibility="public">
+        <out>
+            <xsl:call-template name="sub"/>
+        </out>
+    </xsl:template>
+    
+    <xsl:function name="f:divide" visibility="public">
+        <xsl:param name='x'/>
+        <xsl:param name="y"/>
+        <xsl:sequence select="$x div $y"/>
+    </xsl:function>
+    
+
+</xsl:package>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/function-lookup/function-lookup-005a.xsl	Wed Apr 25 09:59:32 2018 +0100
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:package xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    name="http://function-lookup-005a/"
+    package-version="1.0"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    exclude-result-prefixes="xs"
+    xmlns:f="http://local/"
+    version="3.0"
+    expand-text="yes">
+    
+    <xsl:template name="sub" visibility="public">
+        <sub>
+            <multiply exists="{exists(function-lookup(QName('http://local/', 'multiply'), 2))}"/>
+            <divide exists="{exists(function-lookup(QName('http://local/', 'divide'), 2))}"/>
+            <add exists="{exists(function-lookup(QName('http://local/', 'add'), 2))}" effect="{function-lookup(QName('http://local/', 'add'), 2)(3,4)}"/>
+            <subtract exists="{exists(function-lookup(QName('http://local/', 'subtract'), 2))}"/>
+        </sub>
+    </xsl:template>
+ 
+    
+    <xsl:function name="f:multiply" visibility="private">
+        <xsl:param name='x'/>
+        <xsl:param name="y"/>
+        <xsl:sequence select="$x * $y"/>
+    </xsl:function>
+    
+    <xsl:function name="f:add" visibility="public">
+        <xsl:param name='x'/>
+        <xsl:param name="y"/>
+        <xsl:sequence select="$x + $y"/>
+    </xsl:function>
+    
+    <xsl:function name="f:subtract" visibility="abstract">
+        <xsl:param name='x'/>
+        <xsl:param name="y"/>
+    </xsl:function>
+
+</xsl:package>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/function-lookup/function-lookup-006.xsl	Wed Apr 25 09:59:32 2018 +0100
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:package xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    name="http://function-lookup-005/"
+    package-version="1.0"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    exclude-result-prefixes="xs"
+    xmlns:f="http://local/"
+    version="3.0"
+    expand-text="yes">
+    
+    <xsl:use-package name="http://function-lookup-005a/">
+        <xsl:override>
+            <xsl:function name="f:add" visibility="public">
+                <xsl:param name='x'/>
+                <xsl:param name="y"/>
+                <xsl:sequence select="$x + $y + (if(exists(function-lookup(QName('http://www.w3.org/1999/XSL/Transform', 'override'), 2))) then 1 else 0)"/>
+            </xsl:function>
+            <xsl:function name="f:subtract" visibility="public">
+                <xsl:param name='x'/>
+                <xsl:param name="y"/>
+                <xsl:sequence select="$x + $y + 1"/>
+            </xsl:function>
+        </xsl:override>
+    </xsl:use-package>
+    
+ 
+    <xsl:template name="main" visibility="public">
+        <out result="{f:add(3,4)}"/>
+    </xsl:template>
+    
+    <xsl:function name="f:divide" visibility="public">
+        <xsl:param name='x'/>
+        <xsl:param name="y"/>
+        <xsl:sequence select="$x div $y"/>
+    </xsl:function>
+    
+
+</xsl:package>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/function-lookup/function-lookup-007.xsl	Wed Apr 25 09:59:32 2018 +0100
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    exclude-result-prefixes="xs"
+    xmlns:f="http://local/"
+    version="3.0"
+    expand-text="yes">
+    
+    <!-- function-lookup with a context-sensitive system function -->
+    
+    <xsl:variable name="words" as="element()*">
+        <word xml:lang="en">horse</word>
+        <word xml:lang="de">pferd</word>
+        <word xml:lang="fr">cheval</word>
+    </xsl:variable>
+       
+    <xsl:template name="xsl:initial-template">
+        <xsl:variable name="testers" as="map(*)">
+            <xsl:map>
+                <xsl:for-each select="$words">
+                    <xsl:map-entry key="string(.)" select="function-lookup(QName('http://www.w3.org/2005/xpath-functions', 'lang'), 1)"/>
+                </xsl:for-each>
+            </xsl:map>
+        </xsl:variable>
+        <out>
+            <xsl:value-of select="$words[$testers(.)('de')]"/>
+        </out>
+    </xsl:template>
+
+
+</xsl:stylesheet>
\ No newline at end of file