From e8322ca988fc20baf7892915e6ccb069b11c608e Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 8 Jan 2022 18:14:59 +0530 Subject: feat(parser): implements or syntax --- tests/basic.spec.ts | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/basic.spec.ts b/tests/basic.spec.ts index d443ce1..150966b 100644 --- a/tests/basic.spec.ts +++ b/tests/basic.spec.ts @@ -6,9 +6,11 @@ import { delimited, } from '../src/parser/utils' import { parser } from '../src/parser' -import { some } from 'fp-ts/Option' +import { none, some } from 'fp-ts/Option' import { Expr } from '../src/types' +const plog = (x: any) => console.log(JSON.stringify(x, null, 2)) + describe('Foobar', () => { it('should do shit', () => { expect(integer('12901')).toEqual(right([12901, ''])) @@ -18,10 +20,10 @@ describe('Foobar', () => { expect(whitespace('a')).toEqual(left(['unable to match', 'a'])) expect(delimited(whitespaces0, integer, whitespaces0)(' 20 ')).toEqual( - right([20, '']) + right([20, '']), ) expect(delimited(whitespaces0, integer, whitespaces0)(' 2 0 ')).toEqual( - right([2, '0 ']) + right([2, '0 ']), ) }) @@ -40,7 +42,7 @@ describe('Foobar', () => { some(Expr.End(null)), ], '', - ]) + ]), ) expect(parser(/^ \s* \T? \n+ $/.source)).toEqual( @@ -55,7 +57,29 @@ describe('Foobar', () => { some(Expr.End(null)), ], '', - ]) + ]), + ) + + expect(parser(/ \s|\b\T|\n /.source)).toEqual( + right([ + [ + none, + [ + Expr.Or({ + left: Expr.AnyString(null), + right: [ + Expr.AnyBool(null), + Expr.Or({ + left: Expr.Truthy(null), + right: [Expr.AnyNumber(null)], + }), + ], + }), + ], + none, + ], + '', + ]), ) }) }) -- cgit v1.3.1