diff options
| author | Akshay Nair <phenax5@gmail.com> | 2023-08-10 21:27:42 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2023-08-10 21:27:42 +0530 |
| commit | 3854a42db888a58f0452bfb23b6e17df5bf8ad39 (patch) | |
| tree | bc19fbfaaa637467844a99baf8565cb340691346 /tests | |
| parent | db97b1a9c42fe945ca37256f5ee18d52c6aa32b4 (diff) | |
| download | css-everything-3854a42db888a58f0452bfb23b6e17df5bf8ad39.tar.gz css-everything-3854a42db888a58f0452bfb23b6e17df5bf8ad39.zip | |
feat: multi expression parser done
Diffstat (limited to '')
| -rw-r--r-- | tests/parse-expr.spec.ts | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/tests/parse-expr.spec.ts b/tests/parse-expr.spec.ts index 00097a4..875af63 100644 --- a/tests/parse-expr.spec.ts +++ b/tests/parse-expr.spec.ts @@ -1,9 +1,45 @@ -import { parse } from '../src/parse-expr' -import * as P from '../src/utils/parser-comb' +import { Expr, parse } from '../src/parse-expr' describe('parser', () => { - it('should die', () => { - const res = parse('hello(test)') - expect(res).toEqual(['hello', '(test, 1)']) + it('should parse function call', () => { + expect(parse('hello()')).toEqual([Expr.Call({ name: 'hello', args: [] })]) + expect(parse('hello ( wow , foo ) ')).toEqual([ + Expr.Call({ + name: 'hello', + args: [Expr.Identifier('wow'), Expr.Identifier('foo')], + }), + ]) + expect(parse('hello(wow,foo)')).toEqual([ + Expr.Call({ + name: 'hello', + args: [Expr.Identifier('wow'), Expr.Identifier('foo')], + }), + ]) + expect(parse('hello(wow,foo, coolio)')).toEqual([ + Expr.Call({ + name: 'hello', + args: [ + Expr.Identifier('wow'), + Expr.Identifier('foo'), + Expr.Identifier('coolio'), + ], + }), + ]) + expect(parse('hello(wow)')).toEqual([ + Expr.Call({ name: 'hello', args: [Expr.Identifier('wow')] }), + ]) + }) + + it('should parse sequential function calls', () => { + expect(parse('hello(world) foo-doo(bar, baz)')).toEqual([ + Expr.Call({ + name: 'hello', + args: [Expr.Identifier('world')], + }), + Expr.Call({ + name: 'foo-doo', + args: [Expr.Identifier('bar'), Expr.Identifier('baz')], + }), + ]) }) }) |
