XSpec unit tests failing on unusual differences

Here should go questions about transforming XML with XSLT and FOP.
Crispness
Posts: 9
Joined: Wed Jan 26, 2011 1:39 pm

XSpec unit tests failing on unusual differences

Post by Crispness »

Hi
I am using OxygenXML to write unit tests for some XSLT stylesheets I am working on.

Two of my tests is failing but I can't see why.

I have separated the failing tests into their own unit test doc and stylesheet

The xspec doc is as follows

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" stylesheet="email-test.xsl">
<x:scenario label="Testing email processing and white space management">
<x:scenario label="email1">
<x:context><email username="info.london" edomname="croports.com"/></x:context>
<x:expect label="inline items"><a href="mailto:info.london@croports.com">info.london@croports.com</a> </x:expect>
</x:scenario>
<x:scenario label="email2">
<x:context><email address="info.london@croports.com"/></x:context>
<x:expect label="inline items"><a href="mailto:info.london@croports.com">info.london@croports.com</a></x:expect>
</x:scenario>
</x:scenario>
</x:description>
and the xslt as follows

Code: Select all

<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
exclude-result-prefixes="xd"
version="2.0">

<xsl:template match="email[@edomname]">
<xsl:variable name="email-addr" select="concat(@username,'@',@edomname)"/>
<a href="{concat('mailto:',$email-addr)}"><xsl:value-of select="$email-addr"/></a><xsl:text> </xsl:text>
</xsl:template>

<xsl:template match="email[@address]">
<xsl:variable name="email-addr" select="@address"/>
<a href="{concat('mailto:',$email-addr)}"><xsl:value-of select="$email-addr"/></a><xsl:text> </xsl:text>
</xsl:template>

</xsl:stylesheet>
The tests were originally part of a much larger test suite as was the xslt but I have simplified it back as much as possible for debugging purposes.

The results of running the xspec are slightly strange - see screenshot
Image
It seems that the xspec processor is adding an addition fullstop at the end of the output

Can anyone either replicate this? Or explain what I'm doing wrong?

Thanks
radu_pisoi
Posts: 404
Joined: Thu Aug 21, 2003 11:36 am
Location: Craiova
Contact:

Re: XSpec unit tests failing on unusual differences

Post by radu_pisoi »

Hi,

The difference between the expected result written in the XSpec file and the XML fragment produced by the XSLT transformation consists of the missing whitespace after the a element in the expected result.

So, both templates from the XSLT stylesheet emit a white-space after the a element with the xsl:text instruction. In the XSpec file, to signal that the white-space after the a element is significant you have to use xml:space="preserve" attribute on the x:expect element.

Code: Select all

<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" stylesheet="email-test.xsl">
<x:scenario label="Testing email processing and white space management">
<x:scenario label="email1">
<x:context><email username="info.london" edomname="croports.com"/></x:context>
<x:expect label="inline items" xml:space="preserve"><a href="mailto:info.london@croports.com">info.london@croports.com</a> </x:expect>
</x:scenario>
<x:scenario label="email2">
<x:context><email address="info.london@croports.com"/></x:context>
<x:expect label="inline items" xml:space="preserve"><a href="mailto:info.london@croports.com">info.london@croports.com</a> </x:expect>
</x:scenario>
</x:scenario>
</x:description>
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Crispness
Posts: 9
Joined: Wed Jan 26, 2011 1:39 pm

Re: XSpec unit tests failing on unusual differences

Post by Crispness »

Is there a way to tell it to ignore whitespace during the tests?
radu_pisoi
Posts: 404
Joined: Thu Aug 21, 2003 11:36 am
Location: Craiova
Contact:

Re: XSpec unit tests failing on unusual differences

Post by radu_pisoi »

No, there is no particular attribute to signal that whitespaces should be preserved other than 'xml:space="preserve"'.
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply