feat: support Jekyll style where, #768

This commit is contained in:
Harttle
2024-11-17 21:33:38 +08:00
committed by Jun Yang
parent 11f013bf24
commit 9107eb1b93
9 changed files with 95 additions and 4 deletions
+22
View File
@@ -484,6 +484,28 @@ describe('filters/array', function () {
Kitchen products:
`)
})
it('should support nil as target', () => {
const scope = { list: [{ foo: 'FOO' }, { bar: 'BAR', type: 2 }] }
return test('{{list | where: "type", nil | json}}', scope, '[{"foo":"FOO"}]')
})
it('should support empty as target', async () => {
const scope = { pages: [{ tags: ['FOO'] }, { tags: [] }, { title: 'foo' }] }
await test('{{pages | where: "tags", empty | json}}', scope, '[{"tags":[]}]')
})
it('should not match string with array', async () => {
const scope = { objs: [{ foo: ['FOO', 'bar'] }] }
await test('{{objs | where: "foo", "FOO" | json}}', scope, '[]')
})
describe('jekyll style', () => {
it('should not match string with array', async () => {
const scope = { objs: [{ foo: ['FOO', 'bar'] }] }
await test('{{objs | where: "foo", "FOO" | json}}', scope, '[{"foo":["FOO","bar"]}]', { jekyllWhere: true })
})
it('should support empty as target', async () => {
const scope = { pages: [{ tags: ['FOO'] }, { tags: [] }, { title: 'foo' }] }
await test('{{pages | where: "tags", empty | json}}', scope, '[{"tags":[]}]', { jekyllWhere: true })
})
})
})
describe('where_exp', function () {
const products = [