Skip to content

Commit

Permalink
Merge pull request #36 from pft/master
Browse files Browse the repository at this point in the history
Add tests for implicitly omitted xml declaration
  • Loading branch information
albanm committed Nov 22, 2015
2 parents 07e2df1 + b48bda0 commit 8d12867
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/libxslt.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,37 @@ describe('node-libxslt', function() {
});
});

describe('implicitly omitted xml-declaration', function() {

it('should be respected by a stylesheet with output method html', function() {
var data='<root><strong></strong><!-- comment on xml data --></root>';
var stylesheetHtmlOut = libxslt.parse(fs.readFileSync('test/resources/implicit-omit-xml-declaration-html-out.xsl', 'utf8'));
var result = stylesheetHtmlOut.apply(data);
result.should.be.type('string');
result.should.not.match(/\?xml/);
result.should.match(/<foo\/>/);
result.should.match(/<strong><\/strong>/);
result.should.match(/&lt;bar\/&gt;/);
result.should.not.match(/\<!-- comment/);
result.should.match(/\<node/);
result.should.match(/with text/);
});

it('should be respected by a stylesheet with output method text', function() {
var data='<root><strong>some text </strong><!-- comment on xml data --></root>';
var stylesheetTextOut = libxslt.parse(fs.readFileSync('test/resources/implicit-omit-xml-declaration-text-out.xsl', 'utf8'));
var result = stylesheetTextOut.apply(data);
result.should.be.type('string');
result.should.not.match(/\?xml/);
result.should.match(/<foo\/>/);
result.should.match(/<bar\/>/);
result.should.not.match(/\<!-- comment/);
result.should.not.match(/\<node/);
result.should.not.match(/\<strong/);
result.should.match(/some text with text/);
});
});

describe('libexslt bindings', function(){
it('should expose EXSLT functions', function(callback){
libxslt.parseFile('test/resources/min-value.xsl', function(err, stylesheet){
Expand Down
10 changes: 10 additions & 0 deletions test/resources/implicit-omit-xml-declaration-html-out.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="no"/>
<xsl:template match="root">
<xsl:text disable-output-escaping="yes"><![CDATA[<foo/>]]></xsl:text>
<xsl:text disable-output-escaping="no"><![CDATA[<bar/>]]></xsl:text>
<xsl:copy-of select="strong"/>
<node>with text</node>
<!-- comment on xslt -->
</xsl:template>
</xsl:stylesheet>
10 changes: 10 additions & 0 deletions test/resources/implicit-omit-xml-declaration-text-out.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="no"/>
<xsl:template match="root">
<xsl:text disable-output-escaping="yes"><![CDATA[<foo/>]]></xsl:text>
<xsl:text disable-output-escaping="no"><![CDATA[<bar/>]]></xsl:text>
<xsl:copy-of select="strong"/>
<node>with text</node>
<!-- comment on xslt -->
</xsl:template>
</xsl:stylesheet>

0 comments on commit 8d12867

Please sign in to comment.