UNPKG

853 BJavaScriptView Raw
1var falafel = require('../');
2var test = require('tape');
3
4test('inspect', function (t) {
5 t.plan(6);
6
7 var src = '(function () {'
8 + 'var xs = [ 1, 2, [ 3, 4 ] ];'
9 + 'var ys = [ 5, 6 ];'
10 + 'g([ xs, ys ]);'
11 + '})()';
12
13 var output = falafel(src, function (node) {
14 if (node.type === 'ArrayExpression') {
15 node.update('fn(' + node.source() + ')');
16 }
17 });
18 t.equal(output.inspect(), output.toString());
19
20 var arrays = [
21 [ 3, 4 ],
22 [ 1, 2, [ 3, 4 ] ],
23 [ 5, 6 ],
24 [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ],
25 ];
26
27 Function(['fn','g'], output)(
28 function (xs) {
29 t.same(arrays.shift(), xs);
30 return xs;
31 },
32 function (xs) {
33 t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
34 }
35 );
36});