aboutsummaryrefslogtreecommitdiff
path: root/tests/eval.spec.ts
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2022-01-08 21:17:10 +0530
committerAkshay Nair <phenax5@gmail.com>2022-01-08 21:17:10 +0530
commitb3b2c39df680f88e1e6d3615245754ae5f0380d0 (patch)
tree4af350ce393244d2c8dbcfdb0bd46cbb91ee41ef /tests/eval.spec.ts
parente246f2341ee13926f4273c6d634cef4fe07f040e (diff)
downloadelxr-b3b2c39df680f88e1e6d3615245754ae5f0380d0.tar.gz
elxr-b3b2c39df680f88e1e6d3615245754ae5f0380d0.zip
feat(eval): implements object property matching
Diffstat (limited to 'tests/eval.spec.ts')
-rw-r--r--tests/eval.spec.ts34
1 files changed, 30 insertions, 4 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 }])
+ })
+})