From fabcd754fbf08302ed960b6b6076e893f5f702f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=A4dler?= Date: Tue, 14 Feb 2023 11:50:02 +0100 Subject: [PATCH] Add support for ParenthesizedExpression in filter function --- src/internalFilter.ts | 10 ++++++++++ test/liqe/filter.ts | 24 ++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/internalFilter.ts b/src/internalFilter.ts index b25f001..17bdc56 100644 --- a/src/internalFilter.ts +++ b/src/internalFilter.ts @@ -257,6 +257,16 @@ export const internalFilter = ( }); } + if (ast.type === 'ParenthesizedExpression') { + return internalFilter( + ast.expression, + rows, + resultFast, + path, + highlights, + ); + } + if (!ast.left) { throw new Error('Expected left to be defined.'); } diff --git a/test/liqe/filter.ts b/test/liqe/filter.ts index 3c3ca2d..9ed377a 100644 --- a/test/liqe/filter.ts +++ b/test/liqe/filter.ts @@ -60,6 +60,16 @@ const persons: readonly Person[] = [ phoneNumber: '404-050-2611', subscribed: true, }, + { + height: 150, + name: 'foo bar', + nick: 'old dog', + }, + { + height: 194, + name: 'fox', + nick: 'quick fox', + }, ]; const testQuery = test.macro((t, expectedResultNames: string[]) => { @@ -90,14 +100,14 @@ test('height:[200 TO 225]', testQuery, ['robert', 'noah']); test('height:[200 TO 225}', testQuery, ['robert']); test('height:{220 TO 225}', testQuery, []); -test('NOT David', testQuery, ['john', 'mike', 'robert', 'noah']); -test('-David', testQuery, ['john', 'mike', 'robert', 'noah']); +test('NOT David', testQuery, ['john', 'mike', 'robert', 'noah', 'foo bar', 'fox']); +test('-David', testQuery, ['john', 'mike', 'robert', 'noah', 'foo bar', 'fox']); test('David OR John', testQuery, ['david', 'john', 'noah']); test('Noah AND John', testQuery, ['noah']); test('John AND NOT Noah', testQuery, ['john']); -test('David OR NOT John', testQuery, ['david', 'mike', 'robert']); +test('David OR NOT John', testQuery, ['david', 'mike', 'robert', 'foo bar', 'fox']); test('John AND -Noah', testQuery, ['john']); -test('David OR -John', testQuery, ['david', 'mike', 'robert']); +test('David OR -John', testQuery, ['david', 'mike', 'robert', 'foo bar', 'fox']); test('name:David OR John', testQuery, ['david', 'john', 'noah']); @@ -131,3 +141,9 @@ test('phoneNumber:"404-050-2611"', testQuery, ['noah']); test('phoneNumber:404', testQuery, ['noah']); test('balance:364', testQuery, ['noah']); + +test('(David)', testQuery, ['david']); +test('(name:david OR name:john)', testQuery, ['david', 'john']); +test('(name:"foo bar" AND nick:"quick fox") OR name:fox', testQuery, ['fox']); +test('(name:fox OR name:"foo bar" AND nick:"old dog")', testQuery, ['foo bar']); +test('(name:fox OR (name:"foo bar" AND nick:"old dog"))', testQuery, ['fox', 'foo bar']);