mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
fix: case should allow multiple values separated by or
This is supported by Shopify liquid.
This commit is contained in:
+6
-1
@@ -17,7 +17,12 @@ export default class extends Tag {
|
|||||||
const values: ValueToken[] = []
|
const values: ValueToken[] = []
|
||||||
while (!token.tokenizer.end()) {
|
while (!token.tokenizer.end()) {
|
||||||
values.push(token.tokenizer.readValueOrThrow())
|
values.push(token.tokenizer.readValueOrThrow())
|
||||||
token.tokenizer.readTo(',')
|
token.tokenizer.skipBlank()
|
||||||
|
if (token.tokenizer.peek() === ',') {
|
||||||
|
token.tokenizer.readTo(',')
|
||||||
|
} else {
|
||||||
|
token.tokenizer.readTo('or')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.branches.push({
|
this.branches.push({
|
||||||
values,
|
values,
|
||||||
|
|||||||
@@ -75,4 +75,20 @@ describe('tags/case', function () {
|
|||||||
const html = await liquid.parseAndRender(src)
|
const html = await liquid.parseAndRender(src)
|
||||||
return expect(html).toBe('firstsecond')
|
return expect(html).toBe('firstsecond')
|
||||||
})
|
})
|
||||||
|
it('should support case with multiple values separated by or', async function () {
|
||||||
|
const src = '{% case 3 %}' +
|
||||||
|
'{% when 1 or 2 or 3 %}1 or 2 or 3' +
|
||||||
|
'{% else %}not 1 or 2 or 3' +
|
||||||
|
'{%endcase%}'
|
||||||
|
const html = await liquid.parseAndRender(src)
|
||||||
|
return expect(html).toBe('1 or 2 or 3')
|
||||||
|
})
|
||||||
|
it('should support case with multiple strings separated by or', async function () {
|
||||||
|
const src = '{% case "or" %}' +
|
||||||
|
'{% when "and" or "or" %}and or or' +
|
||||||
|
'{% else %}not and or or' +
|
||||||
|
'{%endcase%}'
|
||||||
|
const html = await liquid.parseAndRender(src)
|
||||||
|
return expect(html).toBe('and or or')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user