diff options
| author | Akshay Nair <phenax5@gmail.com> | 2022-01-08 21:17:10 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2022-01-08 21:17:10 +0530 |
| commit | b3b2c39df680f88e1e6d3615245754ae5f0380d0 (patch) | |
| tree | 4af350ce393244d2c8dbcfdb0bd46cbb91ee41ef /tests | |
| parent | e246f2341ee13926f4273c6d634cef4fe07f040e (diff) | |
| download | elxr-b3b2c39df680f88e1e6d3615245754ae5f0380d0.tar.gz elxr-b3b2c39df680f88e1e6d3615245754ae5f0380d0.zip | |
feat(eval): implements object property matching
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/eval.spec.ts | 34 | ||||
| -rw-r--r-- | tests/parser.spec.ts | 5 |
2 files changed, 34 insertions, 5 deletions
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 }]) + }) +}) diff --git a/tests/parser.spec.ts b/tests/parser.spec.ts index 1ebd290..4db0894 100644 --- a/tests/parser.spec.ts +++ b/tests/parser.spec.ts @@ -91,7 +91,10 @@ describe('Foobar', () => { [ none, [ - Expr.PropertyMatch({ name: 'name', exprs: [Expr.AnyString(null), Expr.Truthy(null)] }), + Expr.PropertyMatch({ + name: 'name', + exprs: [Expr.AnyString(null), Expr.Truthy(null)], + }), Expr.PropertyMatch({ name: 'age', exprs: [Expr.AnyNumber(null)] }), ], none, |
