Skip to content

Commit

Permalink
fix: case should allow multiple values separated by or
Browse files Browse the repository at this point in the history
This is supported by Shopify liquid.
  • Loading branch information
ebobby authored and harttle committed Aug 19, 2023
1 parent 4c30c66 commit b8e7e2d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/tags/case.ts
Expand Up @@ -17,7 +17,12 @@ export default class extends Tag {
const values: ValueToken[] = []
while (!token.tokenizer.end()) {
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({
values,
Expand Down
16 changes: 16 additions & 0 deletions test/integration/tags/case.spec.ts
Expand Up @@ -75,4 +75,20 @@ describe('tags/case', function () {
const html = await liquid.parseAndRender(src)
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')
})
})

0 comments on commit b8e7e2d

Please sign in to comment.