mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
feat: support not operator, #575
This commit is contained in:
@@ -377,4 +377,16 @@ describe('Issues', function () {
|
||||
const html = await liquid.parseAndRender(tpl)
|
||||
expect(html).to.match(/\w+, January \d+, 2023 at \d+:\d\d [ap]m [-+]\d\d\d\d/)
|
||||
})
|
||||
it('#575 Add support for Not operator', async () => {
|
||||
const liquid = new Liquid()
|
||||
const tpl = `
|
||||
{% if link and not button %}
|
||||
<a href="{{ link }}">Lot more code here</a>
|
||||
{% else %}
|
||||
<div>Lot more code here</div>
|
||||
{% endif %}`
|
||||
const ctx = { link: 'https://example.com', button: false }
|
||||
const html = await liquid.parseAndRender(tpl, ctx)
|
||||
expect(html.trim()).to.equal('<a href="https://example.com">Lot more code here</a>')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -397,9 +397,11 @@ describe('Tokenizer', function () {
|
||||
it('should read expression `a ==`', () => {
|
||||
const exp = [...new Tokenizer('a ==').readExpressionTokens()]
|
||||
|
||||
expect(exp).to.have.lengthOf(1)
|
||||
expect(exp).to.have.lengthOf(2)
|
||||
expect(exp[0]).to.be.instanceOf(PropertyAccessToken)
|
||||
expect(exp[0].getText()).to.deep.equal('a')
|
||||
expect(exp[1]).to.be.instanceOf(OperatorToken)
|
||||
expect(exp[1].getText()).to.deep.equal('==')
|
||||
})
|
||||
it('should read expression `a==b`', () => {
|
||||
const exp = new Tokenizer('a==b').readExpressionTokens()
|
||||
|
||||
@@ -154,6 +154,13 @@ describe('Expression', function () {
|
||||
const ctx = new Context({ obj: { foo: 'FOO' }, keys: { "what's this": 'foo' } })
|
||||
expect(await toPromise(create('obj[keys["what\'s this"]]').evaluate(ctx, false))).to.equal('FOO')
|
||||
})
|
||||
it('should support not', async function () {
|
||||
expect(await toPromise(create('not 1 < 2').evaluate(ctx))).to.equal(false)
|
||||
})
|
||||
it('not should have higher precedence than and/or', async function () {
|
||||
expect(await toPromise(create('not 1 < 2 or not 1 > 2').evaluate(ctx))).to.equal(true)
|
||||
expect(await toPromise(create('not 1 < 2 and not 1 > 2').evaluate(ctx))).to.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('sync', function () {
|
||||
|
||||
Reference in New Issue
Block a user