Skip to content

Commit

Permalink
tests for empty string scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
tbence94 committed Dec 11, 2019
1 parent c426c95 commit 8953452
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions test/test.filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ describe('Twig.js Filters ->', function () {
const testTemplate = twig({data: '{{ undef|url_encode() }}'});
testTemplate.render().should.equal('');
});
it('should handle empty strings', function () {
const testTemplate = twig({data: '{{ ""|url_encode() }}'});
testTemplate.render().should.equal('');
});
it('should handle special characters', function () {
const data = {foo: '<foo> \\&"\'.,-_?/Ķä€台北[]{}\t\r\n\b\u0080'};
const testTemplate = twig({data: '{{ foo|url_encode() }}'});
Expand Down Expand Up @@ -183,6 +187,11 @@ describe('Twig.js Filters ->', function () {
const testTemplate = twig({data: '{{ undef|keys }}'});
testTemplate.render().should.equal('');
});

it('should handle empty strings', function () {
const testTemplate = twig({data: '{{ ""|keys }}'});
testTemplate.render().should.equal('');
});
});
describe('merge ->', function () {
it('should merge two objects into an object', function () {
Expand Down Expand Up @@ -216,11 +225,14 @@ describe('Twig.js Filters ->', function () {
testTemplate = twig({data: '{{ [1+ 5,2,4,76]|join("-" ~ ".") }}'});
testTemplate.render().should.equal('6-.2-.4-.76');
});

it('should handle undefined', function () {
const testTemplate = twig({data: '{{ undef|join }}'});
testTemplate.render().should.equal('');
});
it('should handle empty strings', function () {
const testTemplate = twig({data: '{{ ""|join }}'});
testTemplate.render().should.equal('');
});
});

// Other
Expand Down Expand Up @@ -334,6 +346,11 @@ describe('Twig.js Filters ->', function () {
const testTemplate = twig({data: '{{ undef|replace }}'});
testTemplate.render().should.equal('');
});

it('should handle empty strings', function () {
const testTemplate = twig({data: '{{ ""|replace }}'});
testTemplate.render().should.equal('');
});
});

describe('format ->', function () {
Expand All @@ -347,6 +364,11 @@ describe('Twig.js Filters ->', function () {
testTemplate.render().should.equal('');
});

it('should handle empty strings', function () {
const testTemplate = twig({data: '{{ ""|format }}'});
testTemplate.render().should.equal('');
});

it('should handle positive leading sign without padding', function () {
const template = twig({data: '{{ "I like positive numbers like %+d."|format(123) }}'});
template.render({foo: 'foo'}).should.equal('I like positive numbers like +123.');
Expand Down Expand Up @@ -388,6 +410,11 @@ describe('Twig.js Filters ->', function () {
const testTemplate = twig({data: '{{ undef|striptags }}'});
testTemplate.render().should.equal('');
});

it('should handle empty strings', function () {
const testTemplate = twig({data: '{{ ""|striptags }}'});
testTemplate.render().should.equal('');
});
});

describe('escape ->', function () {
Expand All @@ -401,6 +428,11 @@ describe('Twig.js Filters ->', function () {
testTemplate.render().should.equal('');
});

it('should handle empty strings', function () {
const testTemplate = twig({data: '{{ ""|escape }}'});
testTemplate.render().should.equal('');
});

it('should not escape twice if autoescape is on', function () {
twig({
autoescape: true,
Expand Down Expand Up @@ -495,9 +527,9 @@ describe('Twig.js Filters ->', function () {
testTemplate.render().should.equal('');
});

it('should not fail when passed str', function () {
const testTemplate = twig({data: '{{ myemptystr|nl2br }}'});
testTemplate.render({myemptystr: ''}).should.equal('');
it('should handle empty strings', function () {
const testTemplate = twig({data: '{{ ""|nl2br }}'});
testTemplate.render().should.equal('');
});

it('should not escape br tags if autoescape is on', function () {
Expand Down Expand Up @@ -543,6 +575,11 @@ describe('Twig.js Filters ->', function () {
testTemplate.render().should.equal('');
});

it('should handle empty strings', function () {
const testTemplate = twig({data: '{{ ""|trim }}'});
testTemplate.render().should.equal('');
});

it('should not autoescape', function () {
const template = twig({data: '{{ test|trim }}'});
template.render({test: '\r\n <a href="">Test</a>\n '}).should.equal('<a href="">Test</a>');
Expand Down

0 comments on commit 8953452

Please sign in to comment.