diff options
| author | Akshay Nair <phenax5@gmail.com> | 2023-08-20 11:29:07 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2023-08-20 11:29:07 +0530 |
| commit | f61677bbc3ae32cc460014cffe4d9ae9264291c5 (patch) | |
| tree | af7f8935ba15364699f1b1abf6a5987b61011d33 /tests | |
| parent | 2b94b07fdc8f1a82f507b99000add9b7dca2c3d8 (diff) | |
| download | css-everything-f61677bbc3ae32cc460014cffe4d9ae9264291c5.tar.gz css-everything-f61677bbc3ae32cc460014cffe4d9ae9264291c5.zip | |
feat: function declaration
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/eval.spec.ts | 60 |
1 files changed, 56 insertions, 4 deletions
diff --git a/tests/eval.spec.ts b/tests/eval.spec.ts index 660f0b9..d61a470 100644 --- a/tests/eval.spec.ts +++ b/tests/eval.spec.ts @@ -1,5 +1,5 @@ -import { EvalActions, evalExpr } from '../src/eval' -import { Expr } from '../src/parser' +import { EvalActions, EvalValue, evalExpr } from '../src/eval' +import { Expr, exprParser, parseExpr } from '../src/parser' describe('eval', () => { const deps: EvalActions = { @@ -20,8 +20,60 @@ describe('eval', () => { callMethod: jest.fn(), } - fit('should do stuff', () => { - console.log('yo') + fdescribe('function/call', () => { + it('should declare function correctly', async () => { + const evalValue = await evalExpr( + parseExpr(`func(if(get-var(--bool), 'false', 'true'))`), + deps, + ) + expect(evalValue).toEqual( + EvalValue.Lazy([ + Expr.Call({ + name: 'if', + args: [ + Expr.Call({ + name: 'get-var', + args: [Expr.VarIdentifier('--bool')], + }), + Expr.LiteralString('false'), + Expr.LiteralString('true'), + ], + }), + ]), + ) + }) + + it('should allow multiple expressions in func', async () => { + const evalValue = await evalExpr( + parseExpr(`func( + update(--some-var, 'hello world'), + if(get-var(--bool), 'false', 'true') + )`), + deps, + ) + expect(evalValue).toEqual( + EvalValue.Lazy([ + Expr.Call({ + name: 'update', + args: [ + Expr.VarIdentifier('--some-var'), + Expr.LiteralString('hello world'), + ], + }), + Expr.Call({ + name: 'if', + args: [ + Expr.Call({ + name: 'get-var', + args: [Expr.VarIdentifier('--bool')], + }), + Expr.LiteralString('false'), + Expr.LiteralString('true'), + ], + }), + ]), + ) + }) }) it('should add classes', async () => { |
