diff options
| author | Akshay Nair <phenax5@gmail.com> | 2022-01-24 19:19:15 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2022-01-24 19:19:15 +0530 |
| commit | db497bb9950648c056c079c591b239ad4932b5c9 (patch) | |
| tree | a554e54f9a3b0d7d7373874c508831e52ee33416 /tests | |
| parent | a4e2b5b44823571a693ad47250e40efca5f7fe10 (diff) | |
| download | elxr-db497bb9950648c056c079c591b239ad4932b5c9.tar.gz elxr-db497bb9950648c056c079c591b239ad4932b5c9.zip | |
feat(parser): implements min-max quantifier parser
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/parser.spec.ts | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/tests/parser.spec.ts b/tests/parser.spec.ts index 6033040..13a8838 100644 --- a/tests/parser.spec.ts +++ b/tests/parser.spec.ts @@ -14,7 +14,7 @@ import { import { parser } from '../src/parser' import { none, some } from 'fp-ts/Option' import { Expr, Literal } from '../src/types' -import {jlog} from '../src/utils' +import { jlog } from '../src/utils' const wrap = (e: Expr) => right([[none, e, none], '']) const grouped = (l: Expr[]) => wrap(Expr.Group({ exprs: l })) @@ -77,6 +77,37 @@ describe('Parser', () => { '', ]), ) + + expect(parser(/ \s([age \n]{ 2, 5 }) /.source)).toEqual( + grouped([ + Expr.AnyString(), + Expr.MinMax({ + expr: Expr.PropertyMatch({ name: 'age', expr: Expr.AnyNumber() }), + min: 2, + max: 5, + }), + ]), + ) + expect(parser(/ \s([age \n]{ 2, }) /.source)).toEqual( + grouped([ + Expr.AnyString(), + Expr.MinMax({ + expr: Expr.PropertyMatch({ name: 'age', expr: Expr.AnyNumber() }), + min: 2, + max: Infinity, + }), + ]), + ) + expect(parser(/ \s([age \n]{ , 20 }) /.source)).toEqual( + grouped([ + Expr.AnyString(), + Expr.MinMax({ + expr: Expr.PropertyMatch({ name: 'age', expr: Expr.AnyNumber() }), + min: 0, + max: 20, + }), + ]), + ) }) it('should or expressions', () => { @@ -152,7 +183,11 @@ describe('Parser', () => { wrap(Expr.Literal(Literal.String('foobar'))), ) expect(parser(/ "\nwowksadj\n\t wjksdlsd'' !@#%^(&^%$) " /.source)).toEqual( - wrap(Expr.Literal(Literal.String('\\nwowksadj\\n\\t wjksdlsd\'\' !@#%^(&^%$) '))), + wrap( + Expr.Literal( + Literal.String("\\nwowksadj\\n\\t wjksdlsd'' !@#%^(&^%$) "), + ), + ), ) }) |
