UNPKG

1.57 kBJavaScriptView Raw
1var falafel = require('falafel');
2var tape = require('../');
3var tap = require('tap');
4var concat = require('concat-stream');
5
6tap.test('array test', function (tt) {
7 tt.plan(1);
8
9 var test = tape.createHarness();
10
11 test.createStream().pipe(concat(function (rows) {
12 tt.same(rows.toString('utf8'), [
13 'TAP version 13',
14 '# array',
15 'ok 1 should be equivalent',
16 'ok 2 should be equivalent',
17 'ok 3 should be equivalent',
18 'ok 4 should be equivalent',
19 'ok 5 should be equivalent',
20 '',
21 '1..5',
22 '# tests 5',
23 '# pass 5',
24 '',
25 '# ok'
26 ].join('\n') + '\n');
27 }));
28
29 test('array', function (t) {
30 t.plan(5);
31
32 var src = '(' + function () {
33 var xs = [ 1, 2, [ 3, 4 ] ];
34 var ys = [ 5, 6 ];
35 g([ xs, ys ]);
36 } + ')()';
37
38 var output = falafel(src, function (node) {
39 if (node.type === 'ArrayExpression') {
40 node.update('fn(' + node.source() + ')');
41 }
42 });
43
44 var arrays = [
45 [ 3, 4 ],
46 [ 1, 2, [ 3, 4 ] ],
47 [ 5, 6 ],
48 [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ],
49 ];
50
51 Function(['fn','g'], output)(
52 function (xs) {
53 t.same(arrays.shift(), xs);
54 return xs;
55 },
56 function (xs) {
57 t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
58 }
59 );
60 });
61});