From db497bb9950648c056c079c591b239ad4932b5c9 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Mon, 24 Jan 2022 19:19:15 +0530 Subject: feat(parser): implements min-max quantifier parser --- tests/parser.spec.ts | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'tests') 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'' !@#%^(&^%$) "), + ), + ), ) }) -- cgit v1.3.1