Page 1 of 1

XSpec unit tests failing on unusual differences

Posted: Tue Aug 18, 2015 4:22 pm
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

Re: XSpec unit tests failing on unusual differences

Posted: Wed Aug 19, 2015 10:52 am
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>

Re: XSpec unit tests failing on unusual differences

Posted: Thu Aug 27, 2015 4:01 pm
by Crispness
Is there a way to tell it to ignore whitespace during the tests?

Re: XSpec unit tests failing on unusual differences

Posted: Fri Aug 28, 2015 9:55 am
by radu_pisoi
No, there is no particular attribute to signal that whitespaces should be preserved other than 'xml:space="preserve"'.