'use strict'; var assert = require('assert'); var fs = require('fs'); var path = require('path'); var pug = require('../'); var perfTest = fs.readFileSync(__dirname + '/fixtures/perf.pug', 'utf8'); try { fs.mkdirSync(__dirname + '/temp'); } catch (ex) { if (ex.code !== 'EEXIST') { throw ex; } } describe('pug', function() { describe('unit tests with .render()', function() { it('should support doctypes', function() { assert.equal( '', pug.render('doctype xml') ); assert.equal('', pug.render('doctype html')); assert.equal('', pug.render('doctype foo bar baz')); assert.equal('', pug.render('doctype html')); assert.equal('', pug.render('doctype', {doctype: 'html'})); assert.equal( '', pug.render('doctype html', {doctype: 'xml'}) ); assert.equal('', pug.render('html')); assert.equal( '', pug.render('html', {doctype: 'html'}) ); assert.equal( 'foo
', pug.render(Buffer.from('p foo'))); }); it('should support line endings', function() { var src = ['p', 'div', 'img']; var html = ['', '', ''foo'
", pug.render("p 'foo'")); assert.equal("'foo'
", pug.render("p\n | 'foo'")); assert.equal( '', pug.render("- var path = 'foo';\na(href='/' + path)") ); }); it('should support block-expansion', function() { assert.equal( '',
pug.render('pre\n code\n foo\n\n bar')
);
assert.equal('foo\n\nbar
', pug.render('p.\n foo\n\n bar')); assert.equal( 'foo\n\n\n\nbar
', pug.render('p.\n foo\n\n\n\n bar') ); assert.equal( 'foo\n bar\nfoo
', pug.render('p.\n foo\n bar\n foo') ); assert.equal( '', pug.render('script.\n s.parentNode.insertBefore(g,s)\n') ); assert.equal( '', pug.render('script.\n s.parentNode.insertBefore(g,s)') ); }); it('should support tag text', function() { assert.equal('some random text
', pug.render('p some random text')); assert.equal( 'clickGoogle.
', pug.render('p\n | click\n a Google\n | .') ); assert.equal('(parens)
', pug.render('p (parens)')); assert.equal( '(parens)
', pug.render('p(foo="bar") (parens)') ); assert.equal( '', pug.render('option(value="") -- (optional) foo --') ); }); it('should support tag text block', function() { assert.equal( 'foo \nbar \nbaz
', pug.render('p\n | foo \n | bar \n | baz') ); assert.equal( '', pug.render('label\n | Password:\n input') ); assert.equal( '', pug.render('label Password:\n input') ); }); it('should support tag text interpolation', function() { assert.equal( 'yo, pug is cool', pug.render('| yo, #{name} is cool\n', {name: 'pug'}) ); assert.equal( 'yo, pug is cool
', pug.render('p yo, #{name} is cool', {name: 'pug'}) ); assert.equal( 'yo, pug is cool', pug.render('| yo, #{name || "pug"} is cool', {name: null}) ); assert.equal( "yo, 'pug' is cool", pug.render('| yo, #{name || "\'pug\'"} is cool', {name: null}) ); assert.equal( 'foo <script> bar', pug.render('| foo #{code} bar', {code: '', '', '', ].join(''); assert.equal(html, pug.render(str)); }); it('should support comments', function() { // Regular var str = ['//foo', 'p bar'].join('\n'); var html = ['', 'bar
'].join(''); assert.equal(html, pug.render(str)); // Between tags var str = ['p foo', '// bar ', 'p baz'].join('\n'); var html = ['foo
', '', 'baz
'].join(''); assert.equal(html, pug.render(str)); // Quotes var str = "", js = "// script(src: '/js/validate.js') "; assert.equal(str, pug.render(js)); }); it('should support unbuffered comments', function() { var str = ['//- foo', 'p bar'].join('\n'); var html = ['bar
'].join(''); assert.equal(html, pug.render(str)); var str = ['p foo', '//- bar ', 'p baz'].join('\n'); var html = ['foo
', 'baz
'].join(''); assert.equal(html, pug.render(str)); }); it('should support literal html', function() { assert.equal( '', pug.render('') ); }); it('should support code', function() { assert.equal('test', pug.render('!= "test"')); assert.equal('test', pug.render('= "test"')); assert.equal('test', pug.render('- var foo = "test"\n=foo')); assert.equal( 'footestbar', pug.render('- var foo = "test"\n| foo\nem= foo\n| bar') ); assert.equal( 'test