feat: nil/null/empty/blank literals, resolves #102

This commit is contained in:
harttle
2019-02-24 21:50:01 +08:00
parent 54b2adce12
commit 88c9e96392
19 changed files with 355 additions and 52 deletions
+10 -12
View File
@@ -19,22 +19,20 @@ describe('tags/case', function () {
const html = await liquid.parseAndRender(src)
return expect(html).to.equal('foo')
})
it('should resolve empty string if not hit', async function () {
const src = '{% case empty %}' +
'{% when "foo" %}foo{% when ""%}bar' +
'{%endcase%}'
const ctx = {
empty: ''
}
const html = await liquid.parseAndRender(src, ctx)
it('should resolve blank as empty string', async function () {
const src = '{% case blank %}{% when ""%}bar{%endcase%}'
const html = await liquid.parseAndRender(src)
return expect(html).to.equal('bar')
})
it('should resolve empty as empty string', async function () {
const src = '{% case empty %}{% when ""%}bar{%endcase%}'
const html = await liquid.parseAndRender(src)
return expect(html).to.equal('bar')
})
it('should accept empty string as branch name', async function () {
const src = '{% case false %}' +
'{% when "foo" %}foo{% when ""%}bar' +
'{%endcase%}'
const src = '{% case "" %}{% when ""%}bar{%endcase%}'
const html = await liquid.parseAndRender(src)
return expect(html).to.equal('')
return expect(html).to.equal('bar')
})
it('should support boolean case', async function () {
const src = '{% case false %}' +
+2 -2
View File
@@ -1,12 +1,12 @@
import Liquid from 'src/liquid'
import { expect, use } from 'chai'
import * as chaiAsPromised from 'chai-as-promised'
import IContext from 'src/scope/icontext'
import { Context } from 'src/scope/scope'
use(chaiAsPromised)
describe('tags/for', function () {
let liquid: Liquid, ctx: IContext
let liquid: Liquid, ctx: Context
before(function () {
liquid = new Liquid()
liquid.registerTag('throwingTag', {