mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
refactor: rewrite expression evaluation, fix #130
This commit is contained in:
@@ -40,17 +40,17 @@ describe('tags/if', function () {
|
||||
})
|
||||
describe('expression as condition', function () {
|
||||
it('should support ==', async function () {
|
||||
const src = '{% if 2==3 %}yes{%else%}no{%endif%}'
|
||||
const src = '{% if 2 == 3 %}yes{%else%}no{%endif%}'
|
||||
const html = await liquid.parseAndRender(src, ctx)
|
||||
return expect(html).to.equal('no')
|
||||
})
|
||||
it('should support >=', async function () {
|
||||
const src = '{% if 1>=2 and one<two %}a{%endif%}'
|
||||
const src = '{% if 1 >= 2 and one<two %}a{%endif%}'
|
||||
const html = await liquid.parseAndRender(src, ctx)
|
||||
return expect(html).to.equal('')
|
||||
})
|
||||
it('should support !=', async function () {
|
||||
const src = '{% if one!=two %}yes{%else%}no{%endif%}'
|
||||
const src = '{% if one != two %}yes{%else%}no{%endif%}'
|
||||
const html = await liquid.parseAndRender(src, ctx)
|
||||
return expect(html).to.equal('yes')
|
||||
})
|
||||
@@ -60,6 +60,11 @@ describe('tags/if', function () {
|
||||
const html = await liquid.parseAndRender(src, ctx)
|
||||
return expect(html).to.equal('XY')
|
||||
})
|
||||
it('should evaluate right to left', async function () {
|
||||
const src = `{% if false and false or true %}true{%endif%}`
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('')
|
||||
})
|
||||
})
|
||||
describe('comparasion to null', function () {
|
||||
it('should evaluate false for null < 10', async function () {
|
||||
|
||||
@@ -20,17 +20,17 @@ describe('tags/unless', function () {
|
||||
return expect(html).to.equal('yes')
|
||||
})
|
||||
it('should reject when tag not closed', function () {
|
||||
const src = '{% unless 1>2 %}yes'
|
||||
const src = '{% unless 1 > 2 %}yes'
|
||||
return expect(liquid.parseAndRender(src))
|
||||
.to.be.rejectedWith(/tag {% unless 1>2 %} not closed/)
|
||||
.to.be.rejectedWith(/tag {% unless 1 > 2 %} not closed/)
|
||||
})
|
||||
it('should render unless when predicate yields false and else undefined', async function () {
|
||||
const src = '{% unless 1>2 %}yes{%endunless%}'
|
||||
const src = '{% unless 1 > 2 %}yes{%endunless%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('yes')
|
||||
})
|
||||
it('should render "" when predicate yields false and else undefined', async function () {
|
||||
const src = '{% unless 1<2 %}yes{%endunless%}'
|
||||
const src = '{% unless 1 < 2 %}yes{%endunless%}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user