Some new tests for positional pattern matching
authorMichael Kay <mike@saxonica.com>
Wed, 26 Jul 2017 13:46:38 +0100
changeset 1726 460fc782568d
parent 1725 e90178818455
child 1727 4350bd079c18
Some new tests for positional pattern matching
tests/fn/position/_position-test-set.xml
tests/fn/position/position-4102.xsl
tests/fn/position/position-4103.xsl
tests/fn/position/position-4104.xsl
tests/fn/position/position-4105.xsl
--- a/tests/fn/position/_position-test-set.xml	Wed Jul 19 17:31:15 2017 +0100
+++ b/tests/fn/position/_position-test-set.xml	Wed Jul 26 13:46:38 2017 +0100
@@ -273,7 +273,7 @@
       <source role=".">
          <content><![CDATA[<doc>
   <a mark="a1"/>
-  <b mark="b1"/>
+  <b mark="b1"><bb/></b>
   <c mark="c1"/>
   <c mark="c2"/>
   <a mark="a2"/>
@@ -2848,6 +2848,67 @@
       </result>
    </test-case>
 
+   <test-case name="position-4102">
+      <description>position() used in pattern predicate: scope for optimization</description>
+      <created by="Michael Kay" on="2017-07-23"/>
+      <environment ref="position-41"/>
+      <dependencies>
+         <spec value="XSLT10+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="position-4102.xsl"/>
+      </test>
+      <result>
+         <assert-xml><![CDATA[<out><odd/><even/><odd/><even/><odd/><even/><odd/><even/><odd/></out>]]></assert-xml>
+      </result>
+   </test-case>
+   
+   <test-case name="position-4103">
+      <description>position() used in pattern predicate: scope for optimization</description>
+      <created by="Michael Kay" on="2017-07-23"/>
+      <environment ref="position-41"/>
+      <dependencies>
+         <spec value="XSLT10+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="position-4103.xsl"/>
+      </test>
+      <result>
+         <assert-xml><![CDATA[<out><a-odd/><b-odd/><c-odd/><c-even/><a-even/><a-odd/><b-even/><c-odd/><b-odd/></out>]]></assert-xml>
+      </result>
+   </test-case>
+   
+   <test-case name="position-4104">
+      <description>position() used in pattern predicate using the descendant axis</description>
+      <created by="Michael Kay" on="2017-07-26"/>
+      <environment ref="position-41"/>
+      <dependencies>
+         <spec value="XSLT30+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="position-4104.xsl"/>
+      </test>
+      <result>
+         <assert-xml><![CDATA[<out><odd/><even/><even/><odd/><even/><odd/><even/><odd/><even/></out>]]></assert-xml>
+      </result>
+   </test-case>
+   
+   <test-case name="position-4105">
+      <description>position() used in pattern predicate in for-each-group: scope for optimization</description>
+      <created by="Michael Kay" on="2017-07-26"/>
+      <environment ref="position-41"/>
+      <dependencies>
+         <spec value="XSLT20+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="position-4105.xsl"/>
+      </test>
+      <result>
+         <assert-xml><![CDATA[<out><group><a mark="a1"/><b mark="b1"><bb/></b></group><group><c mark="c1"/><c mark="c2"/></group
+            ><group><a mark="a2"/><a mark="a3"/></group><group><b mark="b2"/><c mark="c3"/></group><group><b mark="b3"/></group></out>]]></assert-xml>
+      </result>
+   </test-case>
+   
    <test-case name="position-4201">
       <description>Section: 4.1</description>
       <created by="Michael Kay" on="2012-11-07"/>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/position/position-4102.xsl	Wed Jul 26 13:46:38 2017 +0100
@@ -0,0 +1,23 @@
+<?xml version="1.0"?> 
+<?spec fo#func-position?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
+
+  <!-- Purpose: Exercise potential optimization when position() appears in a predicate. -->
+
+  <xsl:output method="xml" indent="no" encoding="UTF-8"/>
+
+  <xsl:template match="doc">
+    <out>
+      <xsl:apply-templates select="*"/>
+    </out>
+  </xsl:template>
+
+  <xsl:template match="doc/*[position() mod 2 = 0]">
+    <even/>
+  </xsl:template>
+
+  <xsl:template match="doc/*[position() mod 2 = 1]">
+    <odd/>
+  </xsl:template>
+
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/position/position-4103.xsl	Wed Jul 26 13:46:38 2017 +0100
@@ -0,0 +1,39 @@
+<?xml version="1.0"?> 
+<?spec fo#func-position?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
+
+  <!-- Purpose: Exercise potential optimization when position() appears in a predicate. -->
+
+  <xsl:output method="xml" indent="no" encoding="UTF-8"/>
+
+  <xsl:template match="doc">
+    <out>
+      <xsl:apply-templates select="*"/>
+    </out>
+  </xsl:template>
+
+  <xsl:template match="doc/a[position() mod 2 = 0]">
+    <a-even/>
+  </xsl:template>
+
+  <xsl:template match="doc/a[position() mod 2 = 1]">
+    <a-odd/>
+  </xsl:template>
+  
+  <xsl:template match="doc/b[position() mod 2 = 0]">
+    <b-even/>
+  </xsl:template>
+  
+  <xsl:template match="doc/b[position() mod 2 = 1]">
+    <b-odd/>
+  </xsl:template>
+  
+  <xsl:template match="doc/c[position() mod 2 = 0]">
+    <c-even/>
+  </xsl:template>
+  
+  <xsl:template match="doc/c[position() mod 2 = 1]">
+    <c-odd/>
+  </xsl:template>
+
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/position/position-4104.xsl	Wed Jul 26 13:46:38 2017 +0100
@@ -0,0 +1,23 @@
+<?xml version="1.0"?> 
+<?spec fo#func-position?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
+
+  <!-- Purpose: Exercise potential optimization when position() appears in a predicate using the descendant axis. -->
+
+  <xsl:output method="xml" indent="no" encoding="UTF-8"/>
+
+  <xsl:template match="doc">
+    <out>
+      <xsl:apply-templates select="*"/>
+    </out>
+  </xsl:template>
+
+  <xsl:template match="doc/descendant::*[position() mod 2 = 0]">
+    <even/>
+  </xsl:template>
+
+  <xsl:template match="doc/descendant::*[position() mod 2 = 1]">
+    <odd/>
+  </xsl:template>
+
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fn/position/position-4105.xsl	Wed Jul 26 13:46:38 2017 +0100
@@ -0,0 +1,19 @@
+<?xml version="1.0"?> 
+<?spec fo#func-position?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
+
+  <!-- Purpose: Exercise potential optimization when position() appears in a predicate. -->
+
+  <xsl:output method="xml" indent="no" encoding="UTF-8"/>
+
+  <xsl:template match="doc">
+    <out>
+      <xsl:for-each-group select="*" group-starting-with="*[position() mod 2 = 1]">
+         <group>
+           <xsl:copy-of select="current-group()"/>
+         </group>
+      </xsl:for-each-group>
+    </out>
+  </xsl:template>
+
+</xsl:stylesheet>