mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
case/when
This commit is contained in:
+3
-3
@@ -16,19 +16,19 @@ describe('filter', function() {
|
||||
});
|
||||
it('should throw when not registered', function() {
|
||||
expect(function() {
|
||||
filter.parse('foo');
|
||||
filter.construct('foo');
|
||||
}).to.throw(/filter foo not found/);
|
||||
});
|
||||
|
||||
it('should register a simple filter', function(){
|
||||
filter.register('foo', x => x.toUpperCase());
|
||||
expect(filter.parse('foo').render('foo', ctx)).to.equal('FOO');
|
||||
expect(filter.construct('foo').render('foo', ctx)).to.equal('FOO');
|
||||
});
|
||||
|
||||
it('should call filter with corrct arguments', function(){
|
||||
var spy = sinon.spy();
|
||||
filter.register('foo', spy);
|
||||
filter.parse('foo: 33').render('foo', ctx);
|
||||
filter.construct('foo: 33').render('foo', ctx);
|
||||
expect(spy).to.have.been.calledWith('foo', 33);
|
||||
});
|
||||
});
|
||||
|
||||
+2
-1
@@ -22,7 +22,8 @@ describe('render', function() {
|
||||
});
|
||||
tagToken = {
|
||||
type: 'tag',
|
||||
value: 'foo bar:x foo:"FOO" num:2.3'
|
||||
value: 'foo bar:x foo:"FOO" num:2.3',
|
||||
name: 'foo'
|
||||
};
|
||||
htmlToken = {
|
||||
type: 'html',
|
||||
|
||||
+16
-4
@@ -9,7 +9,7 @@ var context = require('../context.js');
|
||||
|
||||
describe('tag', function() {
|
||||
var ctx;
|
||||
before(function(){
|
||||
before(function() {
|
||||
ctx = context.factory({
|
||||
foo: 'bar',
|
||||
arr: [2, 1]
|
||||
@@ -19,7 +19,11 @@ describe('tag', function() {
|
||||
|
||||
it('should throw when not registered', function() {
|
||||
expect(function() {
|
||||
tag.parse('foo');
|
||||
tag.construct({
|
||||
type: 'tag',
|
||||
value: 'foo',
|
||||
name: 'foo'
|
||||
});
|
||||
}).to.throw(/tag foo not found/);
|
||||
});
|
||||
|
||||
@@ -44,7 +48,11 @@ describe('tag', function() {
|
||||
tag.register('foo', {
|
||||
render: spy
|
||||
});
|
||||
tag.parse('foo').render(tokens, ctx);
|
||||
tag.construct({
|
||||
type: 'tag',
|
||||
value: 'foo',
|
||||
name: 'foo'
|
||||
}).render(tokens, ctx);
|
||||
expect(spy).to.have.been.called;
|
||||
});
|
||||
|
||||
@@ -54,7 +62,11 @@ describe('tag', function() {
|
||||
tag.register('foo', {
|
||||
render: spy
|
||||
});
|
||||
var t = tag.parse('foo aa:foo bb: arr[0] cc: 2.3');
|
||||
var t = tag.construct({
|
||||
type: 'tag',
|
||||
value: 'foo aa:foo bb: arr[0] cc: 2.3',
|
||||
name: 'foo'
|
||||
});
|
||||
t.render(tokens, ctx);
|
||||
expect(spy).to.have.been.calledWithMatch(tokens, ctx, 'foo', {
|
||||
aa: 'bar',
|
||||
|
||||
+19
-4
@@ -4,16 +4,31 @@ const expect = chai.expect;
|
||||
var liquid = require('..')();
|
||||
|
||||
var ctx = {
|
||||
empty: '',
|
||||
foo: 'bar',
|
||||
arr: [-2, 'a']
|
||||
};
|
||||
|
||||
describe('tags', function() {
|
||||
it('should support assign', function() {
|
||||
test('{% assign foo="bar"%}{{foo}}', 'bar');
|
||||
expect(liquid.render('{% assign foo="bar"%}{{foo}}', ctx)).to.equal('bar');
|
||||
});
|
||||
it('should support case', function() {
|
||||
expect(function() {
|
||||
liquid.render('{% case "foo"%}');
|
||||
}).to.throw(/case "foo" not closed/);
|
||||
expect(liquid.render('{% case "foo"%}' +
|
||||
'{% when "foo" %}foo{% when "bar"%}bar' +
|
||||
'{%endcase%}', ctx)).to.equal('foo');
|
||||
expect(liquid.render('{% case empty %}' +
|
||||
'{% when "foo" %}foo{% when ""%}bar' +
|
||||
'{%endcase%}')).to.equal('bar');
|
||||
expect(liquid.render('{% case false %}' +
|
||||
'{% when "foo" %}foo{% when ""%}bar' +
|
||||
'{%endcase%}')).to.equal('');
|
||||
expect(liquid.render('{% case "a" %}' +
|
||||
'{% when "b" %}b{% when "c"%}c{%else %}d' +
|
||||
'{%endcase%}')).to.equal('d');
|
||||
});
|
||||
});
|
||||
|
||||
function test(src, dst){
|
||||
expect(liquid.render(src, ctx)).to.equal(dst);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user