mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
tag: tablerow
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
var chai = require("chai");
|
||||
var sinonChai = require("sinon-chai");
|
||||
var sinon = require("sinon");
|
||||
var expect = chai.expect;
|
||||
chai.use(sinonChai);
|
||||
|
||||
var liquid = require('..')(), ctx;
|
||||
|
||||
function test(func, cb){
|
||||
try{
|
||||
func();
|
||||
cb({});
|
||||
}
|
||||
catch(e){
|
||||
cb(e);
|
||||
}
|
||||
}
|
||||
|
||||
describe('error', function() {
|
||||
|
||||
it('should throw TokenizationError when tag illegal', function() {
|
||||
test(function(){
|
||||
liquid.render('{% -a %}', {});
|
||||
}, function(err){
|
||||
expect(err.name).to.equal('TokenizationError');
|
||||
expect(err.message).to.equal('illegal tag: {% -a %}');
|
||||
expect(err.input).to.equal('{% -a %}');
|
||||
expect(err.line).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw correct error info', function() {
|
||||
test(function(){
|
||||
liquid.render('{%if true%}\naaa{%endif%}\n{% -a %}\n3', {});
|
||||
}, function(err){
|
||||
expect(err.input).to.equal('{% -a %}');
|
||||
expect(err.line).to.equal(3);
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw ParseError when tag not exist', function() {
|
||||
test(function(){
|
||||
liquid.render('{% a %}', {});
|
||||
}, function(err){
|
||||
expect(err.name).to.equal('ParseError');
|
||||
expect(err.message).to.equal('tag a not found');
|
||||
expect(err.input).to.equal('{% a %}');
|
||||
expect(err.line).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw ParseError when tag not closed', function() {
|
||||
test(function(){
|
||||
liquid.render('{% if %}', {});
|
||||
}, function(err){
|
||||
expect(err.name).to.equal('ParseError');
|
||||
expect(err.message).to.equal('tag {% if %} not closed');
|
||||
expect(err.input).to.equal('{% if %}');
|
||||
expect(err.line).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@@ -136,4 +136,47 @@ describe('tags', function() {
|
||||
test('{% decrement foo %}{%decrement foo%}{{foo}}', '-2');
|
||||
test('{% decrement one %}{{one}}', '0');
|
||||
});
|
||||
|
||||
it('should support tablerow', function() {
|
||||
src = '{% tablerow i in alpha cols:2 %}{{ i }}{% endtablerow %}';
|
||||
dst = '<table>' +
|
||||
'<tr class="row1"><td class="col1">a</td><td class="col2">b</td></tr>' +
|
||||
'<tr class="row2"><td class="col1">c</td></tr>' +
|
||||
'</table>';
|
||||
test(src, dst);
|
||||
});
|
||||
|
||||
it('should support tablerow with range', function() {
|
||||
src = '{% tablerow i in (1..5) cols:2 %}{{ i }}{% endtablerow %}';
|
||||
dst = '<table>' +
|
||||
'<tr class="row1"><td class="col1">1</td><td class="col2">2</td></tr>' +
|
||||
'<tr class="row2"><td class="col1">3</td><td class="col2">4</td></tr>' +
|
||||
'<tr class="row3"><td class="col1">5</td></tr>' +
|
||||
'</table>';
|
||||
test(src, dst);
|
||||
});
|
||||
|
||||
it('tablerow should throw on illegal cols', function() {
|
||||
testThrow('{% tablerow i in (1..5) cols:0 %}{{ i }}{% endtablerow %}',
|
||||
/illegal cols: 0/);
|
||||
testThrow('{% tablerow i in (1..5) %}{{ i }}{% endtablerow %}',
|
||||
/illegal cols: undefined/);
|
||||
});
|
||||
|
||||
it('should support tablerow with limit', function() {
|
||||
src = '{% tablerow i in (1..5) cols:2 limit:3 %}{{ i }}{% endtablerow %}';
|
||||
dst = '<table>' +
|
||||
'<tr class="row1"><td class="col1">1</td><td class="col2">2</td></tr>' +
|
||||
'<tr class="row2"><td class="col1">3</td></tr>' +
|
||||
'</table>';
|
||||
test(src, dst);
|
||||
});
|
||||
|
||||
it('should support tablerow with offset', function() {
|
||||
src = '{% tablerow i in (1..5) cols:2 offset:3 %}{{ i }}{% endtablerow %}';
|
||||
dst = '<table>' +
|
||||
'<tr class="row1"><td class="col1">4</td><td class="col2">5</td></tr>' +
|
||||
'</table>';
|
||||
test(src, dst);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user