test: cases for async variables

This commit is contained in:
Harttle
2022-05-03 13:31:25 +08:00
committed by Harttle
parent 463a165e5e
commit 2f6d84befc
4 changed files with 17 additions and 6 deletions
+3 -3
View File
@@ -2662,9 +2662,9 @@
} }
}, },
"caniuse-lite": { "caniuse-lite": {
"version": "1.0.30001312", "version": "1.0.30001335",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001312.tgz", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001335.tgz",
"integrity": "sha512-Wiz1Psk2MEK0pX3rUzWaunLTZzqS2JYZFzNKqAiJGiuxIjRPLgV6+VDPOg6lQOUxmDwhTlh198JsTTi8Hzw6aQ==", "integrity": "sha512-ddP1Tgm7z2iIxu6QTtbZUv6HJxSaV/PZeSrWFZtbY4JZ69tOeNhBCl3HyRQgeNZKE5AOn1kpV7fhljigy0Ty3w==",
"dev": true "dev": true
}, },
"cardinal": { "cardinal": {
+3 -3
View File
@@ -25,9 +25,9 @@ export class Expression {
const operands: any[] = [] const operands: any[] = []
for (const token of this.postfix) { for (const token of this.postfix) {
if (TypeGuards.isOperatorToken(token)) { if (TypeGuards.isOperatorToken(token)) {
const r = yield operands.pop() const r = operands.pop()
const l = yield operands.pop() const l = operands.pop()
const result = evalOperatorToken(ctx.opts.operators, token, l, r, ctx) const result = yield evalOperatorToken(ctx.opts.operators, token, l, r, ctx)
operands.push(result) operands.push(result)
} else { } else {
operands.push(yield evalToken(token, ctx, lenient && this.postfix.length === 1)) operands.push(yield evalToken(token, ctx, lenient && this.postfix.length === 1))
+6
View File
@@ -142,4 +142,10 @@ describe('tags/if', function () {
const html = liquid.parseAndRenderSync(src, scope) const html = liquid.parseAndRenderSync(src, scope)
return expect(html).to.equal('true') return expect(html).to.equal('true')
}) })
it('should support async variables', async () => {
const src = `{%if var == 'var' %}success{%endif%}`
const scope = { 'var': Promise.resolve('var') }
const html = await liquid.parseAndRender(src, scope)
return expect(html).to.equal('success')
})
}) })
+5
View File
@@ -52,6 +52,11 @@ describe('Liquid', function () {
const src = '{{ foo }}' const src = '{{ foo }}'
return expect(engine.parseAndRender(src, {}, { strictVariables: true })).rejectedWith(/undefined variable/) return expect(engine.parseAndRender(src, {}, { strictVariables: true })).rejectedWith(/undefined variable/)
}) })
it('should support async variables in output', async () => {
const src = '{{ foo }}'
const html = await engine.parseAndRender(src, { foo: Promise.resolve('FOO') })
expect(html).to.equal('FOO')
})
}) })
describe('#express()', function () { describe('#express()', function () {
const liquid = new Liquid({ root: '/root' }) const liquid = new Liquid({ root: '/root' })