fix: post-increment, pre-decrement working on #76

This commit is contained in:
harttle
2018-07-21 22:59:52 +08:00
parent b5cfd2d2c5
commit c3de3fbb19
12 changed files with 146 additions and 92 deletions
+2 -2
View File
@@ -141,7 +141,7 @@ describe('filters', function () {
it('should support split/first', function () {
var src = '{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}' +
'{{ my_array | first }}'
'{{ my_array | first }}'
return test(src, 'apples')
})
@@ -160,7 +160,7 @@ describe('filters', function () {
it('should support split/last', function () {
var src = '{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}' +
'{{ my_array|last }}'
'{{ my_array|last }}'
return test(src, 'tiger')
})
+25 -21
View File
@@ -1,3 +1,4 @@
'use strict'
const Liquid = require('../..')
const chai = require('chai')
const expect = chai.expect
@@ -5,34 +6,37 @@ chai.use(require('chai-as-promised'))
describe('tags/decrement', function () {
var liquid = Liquid()
it('should throw when variable expression illegal', function () {
var src = '{% decrement / %}{{one}}'
var src = '{% decrement / %}{{var}}'
var ctx = {}
return expect(liquid.parseAndRender(src, ctx)).to.be.rejectedWith(/illegal/)
})
it('should support decrement', function () {
var src = '{% decrement one %}{{one}}'
var ctx = {
one: 1
}
return expect(liquid.parseAndRender(src, ctx))
.to.eventually.equal('0')
})
it('should decrement undefined', function () {
var src = '{% decrement empty %}{{empty}}'
it('should decrement undefined variable', function () {
let src = '{% decrement var %}{% decrement var %}{% decrement var %}'
return expect(liquid.parseAndRender(src))
.to.eventually.equal('-1')
.to.eventually.equal('-1-2-3')
})
it('should support decrement multiple times', function () {
var src = '{% decrement foo %}{%decrement foo%}{{foo}}'
var ctx = {
foo: 1
}
return expect(liquid.parseAndRender(src, ctx))
.to.eventually.equal('-1')
it('should decrement defined variable', function () {
let src = '{% decrement var %}{% decrement var %}{% decrement var %}'
let ctx = {'var': 10}
return liquid.parseAndRender(src, ctx)
.then(x => {
expect(x).to.equal('987')
expect(ctx.var).to.equal(7)
})
})
it('should be independent from assign', function () {
let src = '{% assign var=10 %}{% 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')
})
})
+25 -20
View File
@@ -1,32 +1,37 @@
'use strict'
const Liquid = require('../..')
const chai = require('chai')
const expect = chai.expect
chai.use(require('chai-as-promised'))
describe('tags/increment', function () {
var liquid = Liquid()
let liquid = Liquid()
it('should support increment', function () {
var src = '{% increment one %}{{one}}'
var ctx = {
one: 1
}
return expect(liquid.parseAndRender(src, ctx))
.to.eventually.equal('2')
})
it('should increment undefined', function () {
var src = '{% increment empty %}{{empty}}'
it('should increment undefined variable', function () {
let src = '{% increment one %}{% increment one %}{% increment one %}'
return expect(liquid.parseAndRender(src))
.to.eventually.equal('1')
.to.eventually.equal('012')
})
it('should support increment multiple times', function () {
var src = '{% increment foo %}{%increment foo%}{{foo}}'
var ctx = {
foo: 1
}
return expect(liquid.parseAndRender(src, ctx))
.to.eventually.equal('3')
it('should increment defined variable', function () {
let src = '{% increment one %}{% increment one %}{% increment one %}'
let ctx = {one: 7}
return liquid.parseAndRender(src, ctx)
.then(x => {
expect(x).to.equal('789')
expect(ctx.one).to.equal(10)
})
})
it('should be independent from assign', function () {
let src = '{% assign var=10 %}{% 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')
})
})
+1
View File
@@ -260,6 +260,7 @@ describe('error', function () {
.be.rejected
.then(function (err) {
mock.restore()
console.log(err, err.name)
expect(err.name).to.equal('RenderError')
expect(err.file).to.equal(path.resolve('/foo.html'))
})