test of document root template match

114 views
Skip to first unread message

r.gro...@gmail.com

unread,
Mar 9, 2017, 4:34:18 PM3/9/17
to XSpec
hi group,

I use xspec always to test bug fixes on my company's style sheet. They helped me a lot, especially when it comes to old features: some 'fixes' appear to break them. And this is revealed by the old xspec tests. A real life saver.

One of the last bug fixes was in the template with match='/'.
It looks that this template is never executed by xspec and there is no way to activate it. Is this true?  I have written a small test to show the problem:

stylesheet:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   
version="2.0">

 
<xsl:template match="/">
   
<document>
     
<xsl:apply-templates/>
   
</document>
 
</xsl:template>

 
<xsl:template match="phrases">
   
<xsl:apply-templates/>
 
</xsl:template>

 
<xsl:template match="phrase">
   
<phrase><xsl:apply-templates/></phrase>
 
</xsl:template>
</xsl:stylesheet>

xspec test:


<?xml version="1.0" encoding="UTF-8"?>

<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec"
       
stylesheet="d.xslt">
 
<x:scenario label="When processing a list of phrases">
   
<x:context>
     
<phrases>
       
<phrase>Hello!</phrase>
     
</phrases>
   
</x:context>
   
<!-- check the result -->
   
<x:expect label="document element should be added">
     
<document>
       
<phrase status="same">Hello!</phrase>
     
</document>
   
</x:expect>
 
</x:scenario>
</x:description>


What I try to test here is the code in the match='/' template. So the addding of node 'document'. But this test fails, because the template is not executed by xspec.

I expect it is simply not possible. My next question is: is there a way to change the stylesheet so that xspec can test the underlying code just the same?
What do you do to test the whole stylesheet?

thanks for your insights, Ruud

Sandro Cirulli

unread,
Apr 10, 2017, 4:48:49 PM4/10/17
to XSpec
Hi Ruud,

sorry for the late reply, I just noticed your message now. I'm glad you find XSpec useful. The new release of XSpec (v0.5.0) is available at https://github.com/xspec/xspec/releases. You can also pull the latest code from GitHub (master branch) at https://github.com/xspec/xspec, this contains bug fixes and new features that will appear in the next XSpec release. I'm basing my reply on the latter but this should work with previous versions too.

If you modify your XSpec test as follows:

<?xml version="1.0" encoding="UTF-8"?>
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" stylesheet="d.xsl">

   
<x:scenario label="When processing a list of phrases">

       
<x:context select="/">

           
<phrases>
               
<phrase>Hello!</phrase>
           
</phrases>
       
</x:context>
       
<!-- check the result -->
       
<x:expect label="document element should be added">
           
<document>

               
<phrase>Hello!</phrase>

           
</document>
       
</x:expect>
   
</x:scenario>
</x:description>

you should get a passing test. Note that:

- I added the attribute select="/" in  <context>. This allows you to select a particular node (the root node in this case). This also works if you add <document> inside <context> (it may actually be clearer to provide such a context). For more information on the select attribute, see the documentation at https://github.com/xspec/xspec/wiki/Writing-Scenarios#matching-scenarios)
- I removed attribute status="same" from <phrase>. As your stylesheet does not have a match template for attributes, this will never be converted.

I hope this helps...

Sandro

Sandro Cirulli

unread,
Apr 10, 2017, 4:49:24 PM4/10/17
to XSpec
I replied to this in the previous email thread.

Sandro
Reply all
Reply to author
Forward
0 new messages