diff options
| author | Akshay Nair <phenax5@gmail.com> | 2022-01-13 21:20:35 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2022-01-13 21:42:11 +0530 |
| commit | ba94e799aa352c2fd472b694c745388e3e9feee8 (patch) | |
| tree | e27c99304ed0268f6c9f8c438ae1d17dd269557a /tests/basic.spec.ts | |
| parent | 016821207f1f2294dd09935a4c1d14d78ff3aed1 (diff) | |
| download | elxr-ba94e799aa352c2fd472b694c745388e3e9feee8.tar.gz elxr-ba94e799aa352c2fd472b694c745388e3e9feee8.zip | |
feat(eval): implements or
Diffstat (limited to 'tests/basic.spec.ts')
| -rw-r--r-- | tests/basic.spec.ts | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/tests/basic.spec.ts b/tests/basic.spec.ts index 9336841..3c49267 100644 --- a/tests/basic.spec.ts +++ b/tests/basic.spec.ts @@ -16,20 +16,22 @@ describe('Basic tests', () => { // jlog(matchAll(/[age \n]+/, [ {}, { age: 1 }, '' ])) // jlog(matchAll(/([age \n])+/, [ {}, { age: 1 }, { age: 2 }, { age: 0 }, '' ])) // jlog(matchAll(/\n+/, [ '', 1, 2, 0, '6', 5, '' ])) - - jlog(matchAll(/ -2.05|2|true|\s|\T /, [ 2, -2.05, 5, -2.05, 2.05, 0.05, 'wow', '-2.05', '-2' ])) }) describe('matchAll', () => { - it ('should match literals', () => { - expect(matchAll(/ -2.05 /, [ 2, NaN, -2.05, '-2.05', -2.05, 2.05 ]).groups).toEqual([ + it('should match literals', () => { + expect( + matchAll(/ -2.05 /, [2, NaN, -2.05, '-2.05', -2.05, 2.05]).groups, + ).toEqual([ { value: -2.05, index: 2 }, { value: -2.05, index: 4 }, ]) - expect(matchAll(/ true /, [ 1, true, false, true, 'true' ]).groups).toEqual([ - { value: true, index: 1 }, - { value: true, index: 3 }, - ]) + expect(matchAll(/ true /, [1, true, false, true, 'true']).groups).toEqual( + [ + { value: true, index: 1 }, + { value: true, index: 3 }, + ], + ) }) it('should match simple expression', () => { @@ -87,5 +89,36 @@ describe('Basic tests', () => { { value: [{ num: 3 }], index: 5 }, ]) }) + + it('should match alternatives', () => { + expect( + matchAll(/ -2.01|true|\s\T /, [-2.01, true, false, 'foobar', '']) + .groups, + ).toEqual([ + { value: -2.01, index: 0 }, + { value: true, index: 1 }, + { value: 'foobar', index: 3 }, + ]) + + expect( + matchAll(/ [v 1|2|\s\T|3]+ /, [ + { v: 1 }, + { v: 3 }, + { v: 2 }, + null, + { v: 3 }, + { v: 2 }, + { v: 'wow' }, + { v: '' }, + 2, + 3, + { v: 1 }, + ]).groups, + ).toEqual([ + { value: [{ v: 1 }, { v: 3 }, { v: 2 }], index: 0 }, + { value: [{ v: 3 }, { v: 2 }, { v: 'wow' }], index: 4 }, + { value: [{ v: 1 }], index: 10 }, + ]) + }) }) }) |
