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
+21
View File
@@ -0,0 +1,21 @@
import Liquid from '../..'
import { expect, use } from 'chai'
import * as chaiAsPromised from 'chai-as-promised'
use(chaiAsPromised)
describe('drop', function () {
var engine: Liquid
beforeEach(function () {
engine = new Liquid()
})
it('should test blank strings', async function () {
const src = `
{% unless settings.fp_heading == blank %}
<h1>{{ settings.fp_heading }}</h1>
{% endunless %}`
var ctx = { settings: { fp_heading: '' } }
const html = await engine.parseAndRender(src, ctx)
return expect(html).to.match(/^\s+$/)
})
})
+5
View File
@@ -62,4 +62,9 @@ describe('.parseAndRender()', function () {
const html = await engine.parseAndRender(src)
return expect(html).to.equal('apples')
})
it('should support nil(null, undefined) literal', async function () {
const src = '{% if notexist == nil %}true{% endif %}'
const html = await engine.parseAndRender(src)
expect(html).to.equal('true')
})
})