test: case for {% assign %} invalid value, closes #446

This commit is contained in:
Harttle
2022-03-05 22:09:36 +08:00
parent d3e3fecf53
commit 27e579e0e2
+5 -1
View File
@@ -6,7 +6,7 @@ use(chaiAsPromised)
describe('tags/assign', function () {
const liquid = new Liquid()
it('should throw when variable expression illegal', function () {
it('should throw when variable name illegal', function () {
const src = '{% assign / %}'
const ctx = {}
return expect(liquid.parseAndRender(src, ctx)).to.be.rejectedWith(/illegal/)
@@ -16,6 +16,10 @@ describe('tags/assign', function () {
const html = await liquid.parseAndRender(src)
return expect(html).to.equal('bar')
})
it('should throw when variable value illegal', async function () {
const src = '{% assign foo = “bar” %}'
return expect(liquid.parseAndRender(src)).to.be.rejectedWith(/unexpected token at "“bar”"/)
})
it('should support assign to a number', async function () {
const src = '{% assign foo=10086 %}{{foo}}'
const html = await liquid.parseAndRender(src)