diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/basic.spec.ts | 42 | ||||
| -rw-r--r-- | tests/eval.spec.ts | 74 |
2 files changed, 24 insertions, 92 deletions
diff --git a/tests/basic.spec.ts b/tests/basic.spec.ts index 72c7b40..6fb5921 100644 --- a/tests/basic.spec.ts +++ b/tests/basic.spec.ts @@ -1,24 +1,30 @@ -import { jlog } from '../src/utils' -import { filter, matchAll } from '../src' +import { matchAll } from '../src' describe('Basic tests', () => { - it('should filter shit', () => { - expect(filter(/\s/, [1, '2', 3, '4'])).toEqual(['2', '4']) - expect(filter(/\n/, [1, '2', 3, '4'])).toEqual([1, 3]) - expect(filter(/\T/, [1, 0, '4', ''])).toEqual([1, '4']) - expect(filter(/\F/, [1, 0, '4', ''])).toEqual([0, '']) - expect(filter(/\F\T/, [1, 0, '4', ''])).toEqual([]) - expect(filter(/\s\T/, [1, 0, '4', ''])).toEqual(['4']) - }) - - it('should do it', () => { - // jlog(matchAll(/[age \n]+/, [ {}, { age: 1 }, { age: 2 }, { age: 0 }, '' ])) - // jlog(matchAll(/[age \n]+/, [ {}, { age: 1 }, '' ])) - // jlog(matchAll(/([age \n])+/, [ {}, { age: 1 }, { age: 2 }, { age: 0 }, '' ])) - // jlog(matchAll(/\n+/, [ '', 1, 2, 0, '6', 5, '' ])) - }) - describe('matchAll', () => { + it('should filter shit', () => { + expect(matchAll(/\s/, [1, '2', 3, '4']).groups).toEqual([ + { value: '2', index: 1 }, + { value: '4', index: 3 }, + ]) + expect(matchAll(/\n/, [1, '2', 3, '4']).groups).toEqual([ + { value: 1, index: 0 }, + { value: 3, index: 2 }, + ]) + expect(matchAll(/\T/, [1, 0, '4', '']).groups).toEqual([ + { value: 1, index: 0 }, + { value: '4', index: 2 }, + ]) + expect(matchAll(/\F/, [1, 0, '4', '']).groups).toEqual([ + { value: 0, index: 1 }, + { value: '', index: 3 }, + ]) + expect(matchAll(/\F\T/, [1, 0, '4', '']).groups).toEqual([]) + expect(matchAll(/\s\T/, [1, 0, '4', '']).groups).toEqual([ + { value: '4', index: 2 }, + ]) + }) + it('should match literals', () => { expect( matchAll(/ -2.05 /, [2, NaN, -2.05, '-2.05', -2.05, 2.05]).groups, diff --git a/tests/eval.spec.ts b/tests/eval.spec.ts deleted file mode 100644 index ab91948..0000000 --- a/tests/eval.spec.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { left, right } from 'fp-ts/Either' -import { none, some } from 'fp-ts/Option' -import { Expr, ListExpr } from '../src/types' -import { jlog } from '../src/utils' -import { find, matchAll } from '../src/eval' - -describe('Eval', () => { - it('should do stuff', () => { - const ls = [-1, 1, 2, '3', 4, '5', 6, 7, ''] - - const liexp: ListExpr = [ - none, - Expr.OneOrMore({ - expr: Expr.Group({ - exprs: [Expr.AnyNumber(), Expr.Truthy()], - }), - }), - none, - ] - - //jlog(matchAll(liexp, ls)) - }) - - it('basic evaluation', () => { - const list = [0, 1, '2', 3, [4], 5] - - const liexp: ListExpr = [none, Expr.Group({ exprs: [Expr.AnyNumber(), Expr.Truthy()] }), none] - expect(find(liexp, list)).toEqual([1, 3, 5]) - - const liexp2: ListExpr = [none, Expr.Group({ exprs: [Expr.Falsey(), Expr.Truthy()] }), none] - expect(find(liexp2, list)).toEqual([]) - }) - - it('with groups', () => { - const list = [0, 1, '2', 3, [4], 5] - - const liexp: ListExpr = [ - none, - Expr.Group({ exprs: [ - Expr.AnyItem(), - Expr.Group({ exprs: [Expr.AnyNumber(), Expr.Truthy()] }), - ] }), - 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.Group({ exprs: [ - Expr.PropertyMatch({ - name: 'name', - expr: Expr.Group({ exprs: [Expr.AnyString(), Expr.Truthy()] }), - }), - Expr.PropertyMatch({ - name: 'age', - expr: Expr.Group({ exprs: [Expr.AnyNumber()] }), - }), - ] }), - none, - ] - - expect(find(liexp, list)).toEqual([{ name: 'gello', age: 20 }]) - }) -}) |
