mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-18 14:00:39 -07:00
feat: support filters in if/unless/case, see #287
This commit is contained in:
@@ -76,9 +76,9 @@ describe('tags/assign', function () {
|
||||
return expect(html).to.equal('11')
|
||||
})
|
||||
it('should write to the root scope', async function () {
|
||||
const src = '{%for a in (1..2)%}{%assign num = a%}{{a}}{%endfor%} {{num}}'
|
||||
const src = '{%for a in (1..2)%}{%assign num = a%}{{a}}{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, { num: 1 })
|
||||
return expect(html).to.equal('12 2')
|
||||
return expect(html).to.equal('12')
|
||||
})
|
||||
it('should not change input scope', async function () {
|
||||
const src = '{%for a in (1..2)%}{%assign num = a%}{{a}}{%endfor%} {{num}}'
|
||||
|
||||
@@ -80,6 +80,14 @@ describe('tags/if', function () {
|
||||
return expect(html).to.equal('success')
|
||||
})
|
||||
})
|
||||
describe('filters as condition', function () {
|
||||
it('should support filter on expression', async function () {
|
||||
liquid.registerFilter('negate', (val) => !val)
|
||||
const src = '{% if 2 == 3 | negate %}yes{%else%}no{%endif%}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).to.equal('yes')
|
||||
})
|
||||
})
|
||||
describe('compare to null', function () {
|
||||
it('should evaluate false for null < 10', async function () {
|
||||
const src = '{% if null < 10 %}yes{% else %}no{% endif %}'
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { expect } from 'chai'
|
||||
import * as chai from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
chai.use(chaiAsPromised)
|
||||
const expect = chai.expect
|
||||
|
||||
describe('LiquidOptions#strict*', function () {
|
||||
let engine: Liquid
|
||||
@@ -60,5 +64,9 @@ describe('LiquidOptions#strict*', function () {
|
||||
const html = await engine.render(tpl, ctx, strictLenientOpts)
|
||||
return expect(html).to.equal('a')
|
||||
})
|
||||
it('should not allow undefined variable even if `lenientIf` set', async function () {
|
||||
const tpl = engine.parse('{{notdefined | tolower}}')
|
||||
return expect(() => engine.renderSync(tpl, ctx, strictLenientOpts)).to.throw('undefined variable: notdefined')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user