mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
fix: comparison for empty/nil, fixes #321
This commit is contained in:
@@ -87,4 +87,12 @@ describe('Issues', function () {
|
||||
const html = await engine.parseAndRender(`{{ name | default: "default name" }}`)
|
||||
expect(html).to.equal('default name')
|
||||
})
|
||||
it('#321 comparison for empty/nil', async () => {
|
||||
const engine = new Liquid()
|
||||
const html = await engine.parseAndRender(
|
||||
'{% if empty == nil %}true{%else%}false{%endif%}' +
|
||||
'{% if nil == empty %}true{%else%}false{%endif%}'
|
||||
)
|
||||
expect(html).to.equal('falsefalse')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -79,4 +79,14 @@ describe('drop/empty-drop', function () {
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('true')
|
||||
})
|
||||
it('empty != empty', async function () {
|
||||
const src = '{%if empty == empty %}true{%else%}false{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('false')
|
||||
})
|
||||
it('empty != nil', async function () {
|
||||
const src = '{%if empty == nil %}true{%else%}false{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('false')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -13,22 +13,27 @@ describe('drop/null-drop', function () {
|
||||
const html = await liquid.parseAndRender('{{null}}')
|
||||
expect(html).to.equal('')
|
||||
})
|
||||
it('undefined variable should equal to null', async function () {
|
||||
it('undefined == null', async function () {
|
||||
const src = '{%if foo == nil %}foo == nil{%else%}foo != nil{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('foo == nil')
|
||||
})
|
||||
it('nil equals blank', async function () {
|
||||
const src = '{%if nil == blank %}nil == blank{%else%}nil != blank{% endif %}'
|
||||
it('nil != blank', async function () {
|
||||
const src = '{%if nil == blank %}eq{%else%}neq{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('nil == blank')
|
||||
expect(html).to.equal('neq')
|
||||
})
|
||||
it('0 should not equal to null', async function () {
|
||||
it('nil != empty', async function () {
|
||||
const src = '{%if nil == empty %}eq{%else%}neq{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('neq')
|
||||
})
|
||||
it('0 != null', async function () {
|
||||
const src = '{%if 0 == null %}0 == null{%else%}0 != null{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('0 != null')
|
||||
})
|
||||
it('nil should equal to null', async function () {
|
||||
it('nil == null', async function () {
|
||||
const src = '{%if nil == null %}nil == null{%else%}nil != null{% endif %}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
expect(html).to.equal('nil == null')
|
||||
|
||||
Reference in New Issue
Block a user