Enforce 100% code coverage

This commit is contained in:
kpdecker
2015-08-03 17:28:05 -05:00
parent c3cbaa25a4
commit 324d615726
5 changed files with 47 additions and 15 deletions
+7 -6
View File
@@ -90,7 +90,8 @@ CodeGen.prototype = {
}
},
empty: function(loc = this.currentLocation || {start: {}}) {
empty: function() {
let loc = this.currentLocation || {start: {}};
return new SourceNode(loc.start.line, loc.start.column, this.srcFile);
},
wrap: function(chunk, loc = this.currentLocation || {start: {}}) {
@@ -137,22 +138,22 @@ CodeGen.prototype = {
},
generateList: function(entries, loc) {
let ret = this.empty(loc);
generateList: function(entries) {
let ret = this.empty();
for (let i = 0, len = entries.length; i < len; i++) {
if (i) {
ret.add(',');
}
ret.add(castChunk(entries[i], this, loc));
ret.add(castChunk(entries[i], this));
}
return ret;
},
generateArray: function(entries, loc) {
let ret = this.generateList(entries, loc);
generateArray: function(entries) {
let ret = this.generateList(entries);
ret.prepend('[');
ret.add(']');
+9 -8
View File
@@ -124,19 +124,20 @@ export function prepareBlock(openBlock, program, inverseAndProgram, close, inver
export function prepareProgram(statements, loc) {
if (!loc && statements.length) {
const first = statements[0].loc,
last = statements[statements.length - 1].loc;
const firstLoc = statements[0].loc,
lastLoc = statements[statements.length - 1].loc;
if (first && last) {
/* istanbul ignore else */
if (firstLoc && lastLoc) {
loc = {
source: first.source,
source: firstLoc.source,
start: {
line: first.start.line,
column: first.start.column
line: firstLoc.start.line,
column: firstLoc.start.column
},
end: {
line: last.end.line,
column: last.end.column
line: lastLoc.end.line,
column: lastLoc.end.column
}
};
}
+11
View File
@@ -100,6 +100,10 @@ describe('ast', function() {
});
describe('PartialStatement', function() {
it('provides default params', function() {
var pn = new handlebarsEnv.AST.PartialStatement('so_partial', undefined, {}, {}, LOCATION_INFO);
equals(pn.params.length, 0);
});
it('stores location info', function() {
var pn = new handlebarsEnv.AST.PartialStatement('so_partial', [], {}, {}, LOCATION_INFO);
testLocationInfoStorage(pn);
@@ -113,6 +117,13 @@ describe('ast', function() {
});
});
describe('SubExpression', function() {
it('provides default params', function() {
var pn = new handlebarsEnv.AST.SubExpression('path', undefined, {}, LOCATION_INFO);
equals(pn.params.length, 0);
});
});
describe('Line Numbers', function() {
var ast, body;
+7
View File
@@ -65,6 +65,13 @@ describe('blocks', function() {
shouldCompileTo(string, hash, 'Goodbye cruel sad OMG!');
});
it('works with cached blocks', function() {
var template = CompilerContext.compile('{{#each person}}{{#with .}}{{first}} {{last}}{{/with}}{{/each}}', {data: false});
var result = template({person: [{first: 'Alan', last: 'Johnson'}, {first: 'Alan', last: 'Johnson'}]});
equals(result, 'Alan JohnsonAlan Johnson');
});
describe('inverted sections', function() {
it('inverted sections with unset value', function() {
var string = '{{#goodbyes}}{{this}}{{/goodbyes}}{{^goodbyes}}Right On!{{/goodbyes}}';
+13 -1
View File
@@ -40,5 +40,17 @@ module.exports = function(grunt) {
done();
});
});
grunt.registerTask('test', ['test:bin', 'test:cov']);
grunt.registerTask('test:check-cov', function() {
var done = this.async();
var runner = childProcess.fork('node_modules/.bin/istanbul', ['check-coverage', '--statements', '100', '--functions', '100', '--branches', '100', '--lines 100'], {stdio: 'inherit'});
runner.on('close', function(code) {
if (code != 0) {
grunt.fatal('Coverage check failed: ' + code);
}
done();
});
});
grunt.registerTask('test', ['test:bin', 'test:cov', 'test:check-cov']);
};