Skip to content

Commit

Permalink
fix tests add old node versions support
Browse files Browse the repository at this point in the history
  • Loading branch information
hydiak committed Jul 1, 2016
1 parent f6e4692 commit 56e085b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tests/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
var render = util.render;
var equal = util.equal;
var finish = util.finish;
var repeatString = util.repeatString;

describe('compiler', function() {
it('should compile templates', function(done) {
Expand Down Expand Up @@ -938,7 +939,7 @@

it('should include 200 templates without call stack size exceed', function(done) {
equal('{% include "includeMany.njk" %}',
'FooInclude \n'.repeat(200));
repeatString('FooInclude \n', 200));
finish(done);
});

Expand Down
45 changes: 44 additions & 1 deletion tests/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,61 @@
}
}

function repeatString(string, count) {
if (String.prototype.repeat) {
return String.prototype.repeat.call(string, count);
}

if (string == null) {
throw new TypeError('can\'t convert ' + string + ' to object');
}
var str = '' + string;
count = +count;
if (count !== count) {
count = 0;
}
if (count < 0) {
throw new RangeError('repeat count must be non-negative');
}
if (count === Infinity) {
throw new RangeError('repeat count must be less than infinity');
}
count = Math.floor(count);
if (str.length === 0 || count === 0) {
return '';
}
if (str.length * count >= 1 << 28) {
throw new RangeError('repeat count must not overflow maximum string size');
}
var rpt = '';
for (;;) {
if ((count & 1) === 1) {
rpt += str;
}
count >>>= 1;
if (count === 0) {
break;
}
str += str;
}
return rpt;
}


if(typeof module !== 'undefined') {
module.exports.render = render;
module.exports.equal = equal;
module.exports.finish = finish;
module.exports.normEOL = normEOL;
module.exports.repeatString = repeatString;
}
else {
window.util = {
render: render,
equal: equal,
finish: finish,
normEOL: normEOL
normEOL: normEOL,
repeatString: repeatString
};
}
})();

0 comments on commit 56e085b

Please sign in to comment.