Add fn:replace tests (using special characters in replacement string, with and without 'q' flag)
authordlockett <debbie@saxonica.com>
Wed, 04 Jul 2018 15:45:09 +0100
changeset 1867 688a183e51e2
parent 1866 314fbd0f5415
child 1869 2313e6c2b636
Add fn:replace tests (using special characters in replacement string, with and without 'q' flag)
tests/misc/regex/_regex-test-set.xml
tests/misc/regex/regex-070.xsl
--- a/tests/misc/regex/_regex-test-set.xml	Wed Jun 27 13:14:32 2018 +0100
+++ b/tests/misc/regex/_regex-test-set.xml	Wed Jul 04 15:45:09 2018 +0100
@@ -809,6 +809,255 @@
          <assert-xml file="regex-068.out"/>
       </result>
    </test-case>
+   
+   <environment name="regex070">
+      <source role=".">
+         <content><![CDATA[<doc/>]]></content>
+      </source>
+      <stylesheet file="regex-070.xsl"/>
+   </environment>
+   
+   <test-case name="regex-070a">
+      <description>test replace() with special characters in replacement string.</description>
+      <created by="Debbie Lockett" on="2018-07-02"/>
+      <environment ref="regex070"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <initial-mode name="a"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>/out/A = "Special characters*?*"</assert>
+            <assert>/out/B = "Special characters*?*"</assert>
+            <assert>/out/C = "Special characters*?*"</assert>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="regex-070b">
+      <description>test replace() with special characters in replacement string (with and without
+         'q' flag).</description>
+      <created by="Debbie Lockett" on="2018-07-02"/>
+      <environment ref="regex070"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <initial-mode name="b"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>/out/A = "Special characters$?$"</assert>
+            <assert>/out/B = "Special characters$?$"</assert>
+            <assert>/out/C = "Special characters$?$"</assert>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="regex-070c">
+      <description>test replace() with special characters in replacement string (with and without
+         'q' flag).</description>
+      <created by="Debbie Lockett" on="2018-07-02"/>
+      <environment ref="regex070"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <initial-mode name="c"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>/out/A = "Special characters*\?"</assert>
+            <assert>/out/B = "Special characters*\?"</assert>
+            <assert>/out/C = "Special characters*\?"</assert>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="regex-070d">
+      <description>test replace() with special characters in replacement string (with and without
+         'q' flag).</description>
+      <created by="Debbie Lockett" on="2018-07-02"/>
+      <environment ref="regex070"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <initial-mode name="d"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>/out/A = "Special characters\$\"</assert>
+            <assert>/out/B = "Special characters\$\"</assert>
+            <assert>/out/C = "Special characters\$\"</assert>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="regex-070e">
+      <description>test replace() with special characters in replacement string (with and without
+         'q' flag).</description>
+      <created by="Debbie Lockett" on="2018-07-02"/>
+      <environment ref="regex070"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <initial-mode name="e"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>/out/A = "Special characters*"</assert>
+            <assert>/out/B = "Special characters*"</assert>
+            <assert>/out/C = "Special characters*"</assert>
+            <assert>/out/D = "Special characters$'"</assert>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="regex-070f">
+      <description>test replace() with special characters in replacement string (with and without
+         'q' flag).</description>
+      <created by="Debbie Lockett" on="2018-07-02"/>
+      <environment ref="regex070"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <initial-mode name="f"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>/out/A = "Special characters*"</assert>
+            <assert>/out/B = "Special characters*"</assert>
+            <assert>/out/C = "Special characters*"</assert>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="regex-070g">
+      <description>test replace() with special characters in replacement string.</description>
+      <created by="Debbie Lockett" on="2018-07-02"/>
+      <environment ref="regex070"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <initial-mode name="g"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>/out/A = "Special characters*"</assert>
+            <assert>/out/B = "Special characters*"</assert>
+            <assert>/out/C = "Special characters*"</assert>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="regex-070h">
+      <description>test replace() with special characters in replacement string (with and without
+         'q' flag).</description>
+      <created by="Debbie Lockett" on="2018-07-02"/>
+      <environment ref="regex070"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <initial-mode name="h"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>/out/A = "Special characters*"</assert>
+            <assert>/out/B = "Special characters*"</assert>
+            <assert>/out/C = "Special characters*"</assert>
+            <assert>/out/D = "Special characters*"</assert>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="regex-070i">
+      <description>test replace() with special characters in replacement string.</description>
+      <created by="Debbie Lockett" on="2018-07-02"/>
+      <environment ref="regex070"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <initial-mode name="i"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>/out/A = "Special characters*"</assert>
+            <assert>/out/B = "Special characters*"</assert>
+            <assert>/out/C = "Special characters*"</assert>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="regex-070j">
+      <description>test replace() with special characters in replacement string (with and without
+         'q' flag).</description>
+      <created by="Debbie Lockett" on="2018-07-02"/>
+      <environment ref="regex070"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <initial-mode name="j"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>/out/A = "Special characters*"</assert>
+            <assert>/out/B = "Special characters*"</assert>
+            <assert>/out/C = "Special characters*"</assert>
+            <assert>/out/D = "Special characters*"</assert>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="regex-07k">
+      <description>test replace() with special characters in replacement string (with and without
+         'q' flag).</description>
+      <created by="Debbie Lockett" on="2018-07-02"/>
+      <environment ref="regex070"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <initial-mode name="k"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>/out/A = "Special characters*"</assert>
+            <assert>/out/B = "Special characters*"</assert>
+            <assert>/out/C = "Special characters*"</assert>
+            <assert>/out/D = "Special characters*"</assert>
+         </all-of>
+      </result>
+   </test-case>
+   
+   <test-case name="regex-070l">
+      <description>test replace() with special characters in replacement string (with and without
+         'q' flag).</description>
+      <created by="Debbie Lockett" on="2018-07-02"/>
+      <environment ref="regex070"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <initial-mode name="l"/>
+      </test>
+      <result>
+         <all-of>
+            <assert>/out/A = "Special characters$&amp;"</assert>
+            <assert>/out/B = "Special characters$&amp;"</assert>
+            <assert>/out/C = "Special characters\?"</assert>
+            <assert>/out/D = "Special characters$1"</assert>
+         </all-of>
+      </result>
+   </test-case>
 
    <environment name="regex086">
       <source role=".">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/misc/regex/regex-070.xsl	Wed Jul 04 15:45:09 2018 +0100
@@ -0,0 +1,139 @@
+<?xml version="1.0"?> 
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
+  
+  
+  <!-- PURPOSE: test replace() with special characters in replacement string;
+      with and without use of q flag. -->
+  
+  <xsl:template match="/" mode="a">
+    <xsl:param name="in" select="'Special characters?'"/>
+    <xsl:param name="find" select="'?'"/>
+    <out>
+      <A><xsl:value-of select="replace($in, '\?', '*$0*')"/></A>
+      <B><xsl:value-of select="replace($in, replace($find, '\?', '\\$0'), '*$0*')"/></B>
+      <C><xsl:value-of select="replace($in, replace($find, '[\^\.\\\?\*\+\{\}\(\)\|\$\[\]]',
+        '\\$0'), '*$0*')"/></C>
+    </out>
+  </xsl:template>
+  
+  <xsl:template match="/" mode="b">
+    <xsl:param name="in" select="'Special characters?'"/>
+    <xsl:param name="find" select="'?'"/>
+    <out>
+      <A><xsl:value-of select="replace($in, '\?', '\$$0\$')"/></A>
+      <B><xsl:value-of select="replace($in, replace($find, '\?', '\\?'), '\$$0\$')"/></B>
+      <C><xsl:value-of select="replace($in, replace($find, '?', '\?', 'q'), '\$$0\$')"/></C>
+    </out>
+  </xsl:template>
+  
+  <xsl:template match="/" mode="c">
+    <xsl:param name="in" select="'Special characters\?'"/>
+    <xsl:param name="find" select="'\?'"/>
+    <out>
+      <A><xsl:value-of select="replace($in, '\\\?', '*$0')"/></A>
+      <B><xsl:value-of select="replace($in, replace($find, '\\\?', '\\\\\\?'), '*$0')"/></B>
+      <C><xsl:value-of select="replace($in, replace($find, '\?', '\\\?', 'q'), '*$0')"/></C>
+    </out>
+  </xsl:template>
+  
+  <xsl:template match="/" mode="d">
+    <xsl:param name="in" select="'Special characters$'"/>
+    <xsl:param name="find" select="'$'"/>
+    <out>
+      <A><xsl:value-of select="replace($in, '\$', '\\$0\\')"/></A>
+      <B><xsl:value-of select="replace($in, replace($find, '\$', '\\\$'), '\\$0\\')"/></B>
+      <C><xsl:value-of select="replace($in, replace($find, '$', '\$', 'q'), '\\$0\\')"/></C>
+    </out>
+  </xsl:template>
+  
+  <xsl:template match="/" mode="e">
+    <xsl:param name="in" select="'Special characters$`'"/>
+    <xsl:param name="find" select="'$`'"/>
+    <out>
+      <A><xsl:value-of select="replace($in, '\$`', '*')"/></A>
+      <B><xsl:value-of select="replace($in, replace($find, '\$`', '\\\$`'), '*')"/></B>
+      <C><xsl:value-of select="replace($in, replace($find, '$`', '\$`', 'q'), '*')"/></C>
+      <D><xsl:value-of select="replace($in, replace($find, '$`', '\$`', 'q'), '\$''')"/></D>
+    </out>
+  </xsl:template>
+  
+  <xsl:template match="/" mode="f">
+    <xsl:param name="in" select="'Special characters$0'"/>
+    <xsl:param name="find" select="'$0'"/>
+    <out>
+      <A><xsl:value-of select="replace($in, '\$0', '*')"/></A>
+      <B><xsl:value-of select="replace($in, replace($find, '\$0', '\\\$0'), '*')"/></B>
+      <C><xsl:value-of select="replace($in, replace($find, '$0', '\$0', 'q'), '*')"/></C>
+    </out>
+  </xsl:template>
+  
+  <xsl:template match="/" mode="g">
+    <xsl:param name="in" select="'Special characters$'"/>
+    <xsl:param name="find" select="'$'"/>
+    <out>
+      <A><xsl:value-of select="replace($in, '\$', '*')"/></A>
+      <B><xsl:value-of select="replace($in, replace($find, '\$', '\\$0'), '*')"/></B>
+      <C><xsl:value-of select="replace($in, replace($find, '[\^\.\\\?\*\+\{\}\(\)\|\$\[\]]',
+        '\\$0'), '*')"/></C>
+    </out>
+  </xsl:template>
+  
+  <xsl:template match="/" mode="h">
+    <xsl:param name="in" select="'Special characters$0'"/>
+    <xsl:param name="find" select="'$0'"/>
+    <out>
+      <A><xsl:value-of select="replace($in, '\$0', '*')"/></A>
+      <B><xsl:value-of select="replace($in, replace($find, '\$0', '\\$0'), '*')"/></B>
+      <C><xsl:value-of select="replace($in, replace($find, '[\^\.\\\?\*\+\{\}\(\)\|\$\[\]]0',
+        '\\$0'), '*')"/></C>
+      <D><xsl:value-of select="replace($in, replace($find, '$0', '\$0', 'q'), '*')"/></D>
+    </out>
+  </xsl:template>
+  
+  <xsl:template match="/" mode="i">
+    <xsl:param name="in" select="'Special characters$0'"/>
+    <xsl:param name="find" select="'$0'"/>
+    <out>
+      <A><xsl:value-of select="replace($in, '\$0', '*')"/></A>
+      <B><xsl:value-of select="replace($in, replace($find, '(\$0)', '\\$1'), '*')"/></B>
+      <C><xsl:value-of select="replace($in, replace($find, '([\^\.\\\?\*\+\{\}\(\)\|\$\[\]]0)',
+        '\\$1'), '*')"/></C>
+    </out>
+  </xsl:template>
+  
+  <xsl:template match="/" mode="j">
+    <xsl:param name="in" select="'Special characters$&amp;'"/>
+    <xsl:param name="find" select="'$&amp;'"/>
+    <out>
+      <A><xsl:value-of select="replace($in, '\$&amp;', '*')"/></A>
+      <B><xsl:value-of select="replace($in, replace($find, '\$&amp;', '\\$0'), '*')"/></B>
+      <C><xsl:value-of select="replace($in, replace($find, '[\^\.\\\?\*\+\{\}\(\)\|\$\[\]]&amp;',
+        '\\$0'), '*')"/></C>
+      <D><xsl:value-of select="replace($in, replace($find, '$&amp;', '\$&amp;', 'q'), '*')"/></D>
+    </out>
+  </xsl:template>
+  
+  <xsl:template match="/" mode="k">
+    <xsl:param name="in" select="'Special characters$$'"/>
+    <xsl:param name="find" select="'$$'"/>
+    <out>
+      <A><xsl:value-of select="replace($in, '\$\$', '*')"/></A>
+      <B><xsl:value-of select="replace($in, replace($find, '\$', '\\$0'), '*')"/></B>
+      <C><xsl:value-of select="replace($in, replace($find, '[\^\.\\\?\*\+\{\}\(\)\|\$\[\]]',
+        '\\$0'), '*')"/></C>
+      <D><xsl:value-of select="replace($in, replace($find, '$', '\$', 'q'), '*')"/></D>
+    </out>
+  </xsl:template>
+  
+  <xsl:template match="/" mode="l">
+    <xsl:param name="in" select="'Special characters?'"/>
+    <out>
+      <A><xsl:value-of select="replace($in, '\?', '\$&amp;')"/></A>
+      <B><xsl:value-of select="replace($in, '?', '$&amp;', 'q')"/></B>
+      <C><xsl:value-of select="replace($in, '(\?)', '\\$1')"/></C>
+      <D><xsl:value-of select="replace($in, '?', '$1', 'q')"/></D>
+    </out>
+  </xsl:template>
+  
+</xsl:stylesheet>
\ No newline at end of file