feat: passing liquid to FilterImpl, closes #277

This commit is contained in:
harttle
2020-12-08 00:17:27 +08:00
parent 2bbf50171b
commit f9f595f0f4
11 changed files with 52 additions and 25 deletions
+7 -5
View File
@@ -12,15 +12,17 @@ chai.use(sinonChai)
const expect = chai.expect
describe('Value', function () {
const liquid = {} as any
describe('#constructor()', function () {
const filterMap = new FilterMap(false)
const filterMap = new FilterMap(false, liquid)
it('should parse "foo', function () {
const tpl = new Value('foo', filterMap)
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)
const f = new Value('o | foo: a: "a"', filterMap, 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
@@ -34,10 +36,10 @@ 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)
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)
const tpl = new Value('foo.bar | date: "b" | time:2', filterMap, liquid)
const scope = new Context({
foo: { bar: 'bar' }
})