aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/parse-expr.spec.ts46
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')],
+ }),
+ ])
})
})