feat: export toValueSync & defaultOptions to evaluate expression, see #527

This commit is contained in:
Harttle
2022-08-15 01:53:48 +08:00
committed by Harttle
parent 753e8f94c0
commit e874b4060b
6 changed files with 13 additions and 6 deletions
+7 -1
View File
@@ -1,4 +1,4 @@
import { Liquid, Drop } from '../..'
import { Tokenizer, Context, Liquid, Drop, defaultOptions, toValueSync } from '../..'
import { expect, use } from 'chai'
import * as chaiAsPromised from 'chai-as-promised'
import * as sinon from 'sinon'
@@ -260,4 +260,10 @@ describe('Issues', function () {
const engine = new Liquid()
expect(() => engine.parse('{% assign headshot = https://testurl.com/not_enclosed_in_quotes.jpg %}')).to.throw(/unexpected token at ":/)
})
it('#527 export Liquid Expression', () => {
const tokenizer = new Tokenizer('a > b', defaultOptions.operatorsTrie)
const expression = tokenizer.readExpression()
const result = toValueSync(expression.evaluate(new Context({ a: 1, b: 2 })))
expect(result).to.equal(false)
})
})
+1 -1
View File
@@ -199,7 +199,7 @@ describe('Liquid', function () {
describe('#enderToNodeStream', function () {
const engine = new Liquid()
it('should render a simple value', async () => {
const stream = await engine.renderToNodeStream(engine.parse('{{"foo"}}'))
const stream = engine.renderToNodeStream(engine.parse('{{"foo"}}'))
expect(drainStream(stream)).to.eventually.equal('foo')
})
})
+1 -1
View File
@@ -17,7 +17,7 @@ describe('Tokenizer', function () {
const trie = createTrie(defaultOperators)
it('should read quoted', () => {
expect(new Tokenizer('"foo" ff', trie).readQuoted()!.getText()).to.equal('"foo"')
expect(new Tokenizer('"foo" ff').readQuoted()!.getText()).to.equal('"foo"')
expect(new Tokenizer(' "foo"ff', trie).readQuoted()!.getText()).to.equal('"foo"')
})
it('should read value', () => {