mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-18 22:10:41 -07:00
feat: support filters in if/unless/case, see #287
This commit is contained in:
@@ -1,32 +1,22 @@
|
||||
import * as chai from 'chai'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { QuotedToken } from '../../../src/tokens/quoted-token'
|
||||
import { toThenable } from '../../../src/util/async'
|
||||
import { FilterMap } from '../../../src/template/filter/filter-map'
|
||||
import * as sinonChai from 'sinon-chai'
|
||||
import * as sinon from 'sinon'
|
||||
import { Context } from '../../../src/context/context'
|
||||
import { Value } from '../../../src/template/value'
|
||||
import { createTrie } from '../../../src/util/operator-trie'
|
||||
import { defaultOperators } from '../../../src/types'
|
||||
|
||||
chai.use(sinonChai)
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
describe('Value', function () {
|
||||
const liquid = {
|
||||
options: { operatorsTrie: createTrie(defaultOperators) }
|
||||
} as any
|
||||
const liquid = new Liquid()
|
||||
|
||||
describe('#constructor()', function () {
|
||||
const filterMap = new FilterMap(false, liquid)
|
||||
it('should parse "foo', function () {
|
||||
const tpl = new Value('foo', filterMap, liquid)
|
||||
expect(tpl.initial!.getText()).to.equal('foo')
|
||||
expect(tpl.filters).to.deep.equal([])
|
||||
})
|
||||
it('should parse filters in value content', function () {
|
||||
const f = new Value('o | foo: a: "a"', filterMap, liquid)
|
||||
const f = new Value('o | foo: a: "a"', liquid)
|
||||
expect(f.filters[0].name).to.equal('foo')
|
||||
expect(f.filters[0].args).to.have.lengthOf(1)
|
||||
const [k, v] = f.filters[0].args[0] as any
|
||||
@@ -40,14 +30,13 @@ describe('Value', function () {
|
||||
it('should call chained filters correctly', async function () {
|
||||
const date = sinon.stub().returns('y')
|
||||
const time = sinon.spy()
|
||||
const filterMap = new FilterMap(false, liquid)
|
||||
filterMap.set('date', date)
|
||||
filterMap.set('time', time)
|
||||
const tpl = new Value('foo.bar | date: "b" | time:2', filterMap, liquid)
|
||||
liquid.registerFilter('date', date)
|
||||
liquid.registerFilter('time', time)
|
||||
const tpl = new Value('foo.bar | date: "b" | time:2', liquid)
|
||||
const scope = new Context({
|
||||
foo: { bar: 'bar' }
|
||||
})
|
||||
await toThenable(tpl.value(scope))
|
||||
await toThenable(tpl.value(scope, false))
|
||||
expect(date).to.have.been.calledWith('bar', 'b')
|
||||
expect(time).to.have.been.calledWith('y', 2)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user