mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
fix: increment/decrement independent from capture, #76
This commit is contained in:
+15
-4
@@ -1,25 +1,36 @@
|
||||
'use strict'
|
||||
const Liquid = require('../..')
|
||||
const chai = require('chai')
|
||||
const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('tags/capture', function () {
|
||||
var liquid = Liquid()
|
||||
let liquid = Liquid()
|
||||
|
||||
it('should support capture', function () {
|
||||
var src = '{% capture f %}{{"a" | capitalize}}{%endcapture%}{{f}}'
|
||||
let src = '{% capture f %}{{"a" | capitalize}}{%endcapture%}{{f}}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('A')
|
||||
})
|
||||
|
||||
it('should shading rather than overwriting', function () {
|
||||
let src = '{% capture var %}10{% endcapture %}{{var}}'
|
||||
let ctx = {'var': 20}
|
||||
return liquid.parseAndRender(src, ctx)
|
||||
.then(x => {
|
||||
expect(x).to.equal('10')
|
||||
expect(ctx.var).to.equal(20)
|
||||
})
|
||||
})
|
||||
|
||||
it('should throw on invalid identifier', function () {
|
||||
var src = '{% capture = %}{%endcapture%}'
|
||||
let src = '{% capture = %}{%endcapture%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.be.rejectedWith(/= not valid identifier/)
|
||||
})
|
||||
|
||||
it('should throw when capture not closed', function () {
|
||||
var src = '{%capture c%}{{c}}'
|
||||
let src = '{%capture c%}{{c}}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.be.rejectedWith(/tag .* not closed/)
|
||||
})
|
||||
|
||||
@@ -34,9 +34,27 @@ describe('tags/decrement', function () {
|
||||
.to.eventually.equal('-1-2-3')
|
||||
})
|
||||
|
||||
it('should be independent from capture', function () {
|
||||
let src = '{% capture var %}10{% endcapture %}{% decrement var %}{% decrement var %}{% decrement var %}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('-1-2-3')
|
||||
})
|
||||
|
||||
it('should not shading assign', function () {
|
||||
let src = '{% assign var=10 %}{% decrement var %}{% decrement var %}{% decrement var %} {{var}}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('-1-2-3 10')
|
||||
})
|
||||
|
||||
it('should not shading capture', function () {
|
||||
let src = '{% capture var %}10{% endcapture %}{% decrement var %}{% decrement var %}{% decrement var %} {{var}}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('-1-2-3 10')
|
||||
})
|
||||
|
||||
it('should share the same variable with increment', function () {
|
||||
let src = '{%increment var%}{%increment var%}{%decrement var%}{%decrement var%}{%increment var%}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('01100')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -29,9 +29,21 @@ describe('tags/increment', function () {
|
||||
.to.eventually.equal('012')
|
||||
})
|
||||
|
||||
it('should be independent from capture', function () {
|
||||
let src = '{% capture var %}10{% endcapture %}{% increment var %}{% increment var %}{% increment var %}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('012')
|
||||
})
|
||||
|
||||
it('should not shading assign', function () {
|
||||
let src = '{% assign var=10 %}{% increment var %}{% increment var %}{% increment var %} {{var}}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('012 10')
|
||||
})
|
||||
|
||||
it('should not shading capture', function () {
|
||||
let src = '{% capture var %}10{% endcapture %}{% increment var %}{% increment var %}{% increment var %} {{var}}'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.eventually.equal('012 10')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user