UNPKG

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