1 | var falafel = require('falafel');
|
2 | var tape = require('../');
|
3 | var tap = require('tap');
|
4 |
|
5 | tap.test('array test', function (tt) {
|
6 | tt.plan(1);
|
7 |
|
8 | var test = tape.createHarness({ exit : false });
|
9 | var tc = tap.createConsumer();
|
10 |
|
11 | var rows = [];
|
12 | tc.on('data', function (r) { rows.push(r) });
|
13 | tc.on('end', function () {
|
14 | var rs = rows.map(function (r) {
|
15 | if (r && typeof r === 'object') {
|
16 | return { id : r.id, ok : r.ok, name : r.name.trim() };
|
17 | }
|
18 | else return r;
|
19 | });
|
20 | tt.same(rs, [
|
21 | 'TAP version 13',
|
22 | 'array',
|
23 | { id: 1, ok: true, name: 'should be equivalent' },
|
24 | { id: 2, ok: true, name: 'should be equivalent' },
|
25 | { id: 3, ok: true, name: 'should be equivalent' },
|
26 | { id: 4, ok: true, name: 'should be equivalent' },
|
27 | { id: 5, ok: false, name: 'plan != count' },
|
28 | { id: 6, ok: true, name: 'should be equivalent' },
|
29 | 'tests 6',
|
30 | 'pass 5',
|
31 | 'fail 1'
|
32 | ]);
|
33 | });
|
34 |
|
35 | test.createStream().pipe(tc);
|
36 |
|
37 | test('array', function (t) {
|
38 | t.plan(3);
|
39 |
|
40 | var src = '(' + function () {
|
41 | var xs = [ 1, 2, [ 3, 4 ] ];
|
42 | var ys = [ 5, 6 ];
|
43 | g([ xs, ys ]);
|
44 | } + ')()';
|
45 |
|
46 | var output = falafel(src, function (node) {
|
47 | if (node.type === 'ArrayExpression') {
|
48 | node.update('fn(' + node.source() + ')');
|
49 | }
|
50 | });
|
51 |
|
52 | var arrays = [
|
53 | [ 3, 4 ],
|
54 | [ 1, 2, [ 3, 4 ] ],
|
55 | [ 5, 6 ],
|
56 | [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ],
|
57 | ];
|
58 |
|
59 | Function(['fn','g'], output)(
|
60 | function (xs) {
|
61 | t.same(arrays.shift(), xs);
|
62 | return xs;
|
63 | },
|
64 | function (xs) {
|
65 | t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
|
66 | }
|
67 | );
|
68 | });
|
69 | });
|