aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2022-01-24 19:19:15 +0530
committerAkshay Nair <phenax5@gmail.com>2022-01-24 19:19:15 +0530
commitdb497bb9950648c056c079c591b239ad4932b5c9 (patch)
treea554e54f9a3b0d7d7373874c508831e52ee33416 /tests
parenta4e2b5b44823571a693ad47250e40efca5f7fe10 (diff)
downloadelxr-db497bb9950648c056c079c591b239ad4932b5c9.tar.gz
elxr-db497bb9950648c056c079c591b239ad4932b5c9.zip
feat(parser): implements min-max quantifier parser
Diffstat (limited to 'tests')
-rw-r--r--tests/parser.spec.ts39
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'' !@#%^(&^%$) "),
+ ),
+ ),
)
})