Skip to content

Commit 6e0fd23

Browse files
committed
wip / add tests over functions
1 parent b467b7a commit 6e0fd23

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/functional/functionTests.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var should = require("should");
2+
var parser = require('../../main');
3+
4+
describe('Function tests', function() {
5+
6+
it('test variadic', function () {
7+
// Get result from parser
8+
var ast = parser.parseEval('function &foo($a = 1, array &...$params) {}');
9+
var fn = ast[1][0];
10+
fn[0].should.be.exactly('function');
11+
fn[1].should.be.exactly('foo');
12+
13+
var args = fn[2];
14+
args.length.should.be.exactly(2);
15+
16+
// 1st param
17+
var arg1 = args[0];
18+
arg1[0].should.be.exactly('param');
19+
arg1[1].should.be.exactly('$a');
20+
should.equal(arg1[2], null);
21+
arg1[3][0].should.be.exactly('number');
22+
arg1[3][1].should.be.exactly('1');
23+
arg1[4].should.be.exactly(false, 'not byref');
24+
arg1[5].should.be.exactly(false, 'not variadic');
25+
26+
// 2nd param
27+
var arg2 = args[1];
28+
arg2[0].should.be.exactly('param');
29+
arg2[1].should.be.exactly('$params');
30+
arg2[2][0].should.be.exactly('array');
31+
should.equal(arg2[3], null);
32+
arg2[4].should.be.exactly(true, 'byref');
33+
arg2[5].should.be.exactly(true, 'variadic');
34+
});
35+
36+
});

0 commit comments

Comments
 (0)