Skip to content

Commit

Permalink
Bump test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kpdecker committed Nov 8, 2014
1 parent 83bcbee commit d47e4dd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/handlebars/compiler/helpers.js
Expand Up @@ -98,7 +98,8 @@ export function prepareProgram(statements, isRoot) {
if (omitLeft(statements, i)) {
// If we are on a standalone node, save the indent info for partials
if (current.type === 'partial') {
current.indent = (/([ \t]+$)/).exec(statements[i-1].original) ? RegExp.$1 : '';
// Pull out the whitespace from the final line
current.indent = (/([ \t]+$)/).exec(statements[i-1].original)[1];
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/handlebars/compiler/javascript-compiler.js
Expand Up @@ -732,8 +732,8 @@ JavaScriptCompiler.prototype = {
usedLiteral = true;
} else {
// Get or create the current stack name for use by the inline
createdStack = !this.stackSlot;
var name = !createdStack ? this.topStackName() : this.incrStack();
createdStack = true;
var name = this.incrStack();

prefix = '(' + this.push(name) + ' = ' + top + ')';
stack = this.topStack();
Expand Down
1 change: 1 addition & 0 deletions spec/artifacts/bom.handlebars
@@ -0,0 +1 @@
a
31 changes: 30 additions & 1 deletion spec/precompiler.js
Expand Up @@ -9,27 +9,38 @@ describe('precompiler', function() {

var Handlebars = require('../lib'),
Precompiler = require('../lib/precompiler'),
fs = require('fs'),
uglify = require('uglify-js');

var log,
logFunction,

precompile,
minify;
minify,

file,
content,
writeFileSync;

beforeEach(function() {
precompile = Handlebars.precompile;
minify = uglify.minify;
writeFileSync = fs.writeFileSync;

logFunction = console.log;
log = '';
console.log = function() {
log += Array.prototype.join.call(arguments, '');
};
fs.writeFileSync = function(_file, _content) {
file = _file;
content = _content;
};
});
afterEach(function() {
Handlebars.precompile = precompile;
uglify.minify = minify;
fs.writeFileSync = writeFileSync;
console.log = logFunction;
});

Expand Down Expand Up @@ -121,6 +132,24 @@ describe('precompiler', function() {
equal(log, 'simple\n');
});

it('should handle different root', function() {
Handlebars.precompile = function() { return 'simple'; };
Precompiler.cli({templates: [__dirname + '/artifacts/empty.handlebars'], simple: true, extension: 'handlebars', root: 'foo/'});
equal(log, 'simple\n');
});
it('should output to file system', function() {
Handlebars.precompile = function() { return 'simple'; };
Precompiler.cli({templates: [__dirname + '/artifacts/empty.handlebars'], simple: true, extension: 'handlebars', output: 'file!'});
equal(file, 'file!');
equal(content, 'simple\n');
equal(log, '');
});
it('should handle BOM', function() {
Handlebars.precompile = function(template) { return template === 'a' ? 'simple' : 'fail'; };
Precompiler.cli({templates: [__dirname + '/artifacts/bom.handlebars'], simple: true, extension: 'handlebars', bom: true});
equal(log, 'simple\n');
});

it('should output minimized templates', function() {
Handlebars.precompile = function() { return 'amd'; };
uglify.minify = function() { return {code: 'min'}; };
Expand Down

0 comments on commit d47e4dd

Please sign in to comment.