diff options
| author | Akshay Nair <phenax5@gmail.com> | 2022-01-08 18:14:59 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2022-01-08 18:16:48 +0530 |
| commit | e8322ca988fc20baf7892915e6ccb069b11c608e (patch) | |
| tree | eaef108f21389268d42218eacde2256884a62f64 /tests | |
| parent | e1092bfca260412ab716710d31c24c86d3a818e1 (diff) | |
| download | elxr-e8322ca988fc20baf7892915e6ccb069b11c608e.tar.gz elxr-e8322ca988fc20baf7892915e6ccb069b11c608e.zip | |
feat(parser): implements or syntax
Diffstat (limited to '')
| -rw-r--r-- | tests/basic.spec.ts | 34 |
1 files changed, 29 insertions, 5 deletions
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, + ], + '', + ]), ) }) }) |
