mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
fix: report error for malformed else/elsif/endif/endfor, #713
This commit is contained in:
+2
-10
@@ -471,19 +471,11 @@ describe('Issues', function () {
|
||||
})
|
||||
it('#670 Should not render anything after an else branch', () => {
|
||||
const engine = new Liquid()
|
||||
const result = engine.parseAndRenderSync('{% assign value = "this" %}' +
|
||||
'{% if false %}don\'t show' +
|
||||
'{% else %}show {{ value }}' +
|
||||
'{% else %}don\'t show{% endif %}', {})
|
||||
expect(result).toEqual('show this')
|
||||
expect(() => engine.parseAndRenderSync('{% assign value = "this" %}{% if false %}{% else %}{% else %}{% endif %}')).toThrow('duplicated else')
|
||||
})
|
||||
it('#672 Should not render an elseif after an else branch', () => {
|
||||
const engine = new Liquid()
|
||||
const result = engine.parseAndRenderSync('{% if false %}don\'t show' +
|
||||
'{% else %}show' +
|
||||
'{% elsif true %}don\'t show' +
|
||||
'{% endif %}', {})
|
||||
expect(result).toEqual('show')
|
||||
expect(() => engine.parseAndRenderSync('{% if false %}{% else %}{% elsif true %}{% endif %}')).toThrow('unexpected elsif after else')
|
||||
})
|
||||
it('#675 10.10.1 Operator: contains regression', () => {
|
||||
const engine = new Liquid()
|
||||
|
||||
@@ -78,10 +78,10 @@ describe('tags/for', function () {
|
||||
.rejects.toThrow('illegal tag: {%for c alpha%}, line:1, col:1')
|
||||
})
|
||||
|
||||
it('should reject when inner templates rejected', function () {
|
||||
const src = '{%for c in alpha%}{%throwingTag%}{%endfor%}'
|
||||
it('should throw for additional args', function () {
|
||||
const src = "{% for f in foo %} foo {% else foo = 'blah' %} {% endfor %}"
|
||||
return expect(liquid.parseAndRender(src, scope))
|
||||
.rejects.toThrow(/intended render error/)
|
||||
.rejects.toThrow(`unexpected "foo = 'blah'", line:1, col:1`)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -26,6 +26,12 @@ describe('tags/if', function () {
|
||||
return expect(html).toBe('')
|
||||
})
|
||||
|
||||
it('should throw for additional args', function () {
|
||||
const src = "{% if foo %} foo {% else foo = 'blah' %} {% endif %}"
|
||||
return expect(liquid.parseAndRender(src, scope))
|
||||
.rejects.toThrow(`unexpected "foo = 'blah'", line:1, col:1`)
|
||||
})
|
||||
|
||||
describe('single value as condition', function () {
|
||||
it('should support boolean', async function () {
|
||||
const src = '{% if false %}1{%elsif true%}2{%else%}3{%endif%}'
|
||||
@@ -155,12 +161,12 @@ describe('tags/if', function () {
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).toBe('no')
|
||||
})
|
||||
it('should not render anything after an else branch even when first else branch is empty', () => {
|
||||
const engine = new Liquid()
|
||||
const result = engine.parseAndRenderSync('{% if false %}don\'t show' +
|
||||
'{% else %}' +
|
||||
'{% else %}don\'t show' +
|
||||
'%{% endif %}', {})
|
||||
expect(result).toEqual('')
|
||||
it('should throw for duplicated else', () => {
|
||||
expect(() => liquid.parseAndRenderSync('{% if false %}{% else %}{% else %}{% endif %}'))
|
||||
.toThrow(`duplicated else`)
|
||||
})
|
||||
it('should throw for unexpected elsif', () => {
|
||||
expect(() => liquid.parseAndRenderSync('{% if false %}{% else %}{% elsif true %}{% endif %}'))
|
||||
.toThrow(`unexpected elsif after else`)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user