From b3b2c39df680f88e1e6d3615245754ae5f0380d0 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 8 Jan 2022 21:17:10 +0530 Subject: feat(eval): implements object property matching --- tests/eval.spec.ts | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'tests/eval.spec.ts') diff --git a/tests/eval.spec.ts b/tests/eval.spec.ts index 9bf3000..dada762 100644 --- a/tests/eval.spec.ts +++ b/tests/eval.spec.ts @@ -10,14 +10,14 @@ describe('Eval', () => { const liexp: ListExpr = [ none, - [ Expr.AnyNumber(null), Expr.Truthy(null) ], + [Expr.AnyNumber(null), Expr.Truthy(null)], none, ] expect(find(liexp, list)).toEqual([1, 3, 5]) const liexp2: ListExpr = [ none, - [ Expr.Falsey(null), Expr.Truthy(null) ], + [Expr.Falsey(null), Expr.Truthy(null)], none, ] expect(find(liexp2, list)).toEqual([]) @@ -28,10 +28,36 @@ describe('Eval', () => { const liexp: ListExpr = [ none, - [ Expr.AnyItem(null), Expr.Group({ exprs: [ Expr.AnyNumber(null), Expr.Truthy(null)] }) ], + [ + Expr.AnyItem(null), + Expr.Group({ exprs: [Expr.AnyNumber(null), Expr.Truthy(null)] }), + ], none, ] expect(find(liexp, list)).toEqual([1, 3, 5]) }) -}) + it('object property', () => { + const list = [ + { name: 20, age: 'hello' }, + { name: 'gello', age: 20 }, + { name: '', age: 20 }, + { name: 'Wow' }, + { age: 20 }, + ] + + const liexp: ListExpr = [ + none, + [ + Expr.PropertyMatch({ + name: 'name', + exprs: [Expr.AnyString(null), Expr.Truthy(null)], + }), + Expr.PropertyMatch({ name: 'age', exprs: [Expr.AnyNumber(null)] }), + ], + none, + ] + + expect(find(liexp, list)).toEqual([{ name: 'gello', age: 20 }]) + }) +}) -- cgit v1.3.1