mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 12:20:40 -07:00
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
import * as chai from 'chai'
|
|
import * as sinonChai from 'sinon-chai'
|
|
import Filter from '../../src/filter'
|
|
import Tag from '../../src/tag'
|
|
import Template from '../../src/parser'
|
|
|
|
const expect = chai.expect
|
|
const filter = Filter()
|
|
const tag = Tag()
|
|
chai.use(sinonChai)
|
|
|
|
describe('template', function () {
|
|
let template
|
|
const add = (l, r) => l + r
|
|
|
|
beforeEach(function () {
|
|
filter.clear()
|
|
filter.register('add', add)
|
|
|
|
tag.clear()
|
|
template = Template(tag, filter)
|
|
})
|
|
|
|
it('should throw when value string illegal', function () {
|
|
expect(function () {
|
|
template.parseValue('/')
|
|
}).to.throw(/illegal value string/)
|
|
})
|
|
|
|
it('should parse value string', function () {
|
|
const tpl = template.parseValue('foo')
|
|
expect(tpl.type).to.equal('value')
|
|
expect(tpl.initial).to.equal('foo')
|
|
expect(tpl.filters).to.deep.equal([])
|
|
})
|
|
|
|
it('should parse value string with a simple filter', function () {
|
|
const tpl = template.parseValue('foo | add: 3, "foo"')
|
|
expect(tpl.initial).to.equal('foo')
|
|
expect(tpl.filters.length).to.equal(1)
|
|
expect(tpl.filters[0].filter).to.equal(add)
|
|
})
|
|
|
|
it('should parse value string with filters', function () {
|
|
const tpl = template.parseValue('foo | add: "|" | add')
|
|
expect(tpl.initial).to.equal('foo')
|
|
expect(tpl.filters.length).to.equal(2)
|
|
})
|
|
})
|