feature: strict rendering, close #9

This commit is contained in:
harttle
2016-09-26 23:25:08 +08:00
parent be6c67a1ba
commit 937d213a2d
8 changed files with 101 additions and 68 deletions
-8
View File
@@ -42,14 +42,6 @@ describe('error', function() {
});
});
it('should throw ParseError when filter not exist', function() {
return test(engine.parseAndRender('{{ a | xz }}', {}), function(err){
expect(err.name).to.equal('ParseError');
expect(err.message).to.equal('filter "xz" not found');
expect(err.input).to.equal('{{ a | xz }}');
expect(err.line).to.equal(1);
});
});
it('should throw ParseError when tag not exist', function() {
return test(engine.parseAndRender('{% a %}', {}), function(err){
expect(err.name).to.equal('ParseError');
+4 -4
View File
@@ -14,10 +14,10 @@ describe('filter', function() {
filter.clear();
scope = Scope.factory();
});
it('should throw when not registered', function() {
expect(function() {
filter.construct('foo');
}).to.throw(/filter "foo" not found/);
it('should return undefined when not registered', function() {
var result = filter.construct('foo');
expect(result.name).to.equal('foo');
expect(result.error).to.be.an('Error');
});
it('should parse argument syntax', function(){
+10
View File
@@ -37,6 +37,16 @@ describe('liquid', function() {
it('should output undefined to empty', function() {
return engine.parseAndRender('foo{{zzz}}bar', ctx).should.eventually.equal('foobar');
});
it('should render as null when filter undefined', function() {
return engine.parseAndRender('{{arr | filter1}}', ctx).should.eventually.equal('');
});
it('should throw upon undefined filter when strict_filters set', function() {
var opts = {
strict_filters: true
};
return expect(engine.parseAndRender('{{arr | filter1}}', ctx, opts)).to
.be.rejectedWith(/undefined filter: filter1/);
});
it('should parse html', function() {
(function() {
engine.parse('{{obj}}');