aboutsummaryrefslogtreecommitdiff
path: root/tests/parser.spec.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/parser.spec.ts')
-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'' !@#%^(&^%$) "),
+ ),
+ ),
)
})