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();
|
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 | 'nested array test',
|
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: true, name: 'should be equivalent' },
|
28 | 'inside test',
|
29 | { id: 6, ok: true, name: '(unnamed assert)' },
|
30 | { id: 7, ok: true, name: '(unnamed assert)' },
|
31 | 'another',
|
32 | { id: 8, ok: true, name: '(unnamed assert)' },
|
33 | 'tests 8',
|
34 | 'pass 8',
|
35 | 'ok'
|
36 | ]);
|
37 | });
|
38 |
|
39 | test.createStream().pipe(tc);
|
40 |
|
41 | test('nested array test', function (t) {
|
42 | t.plan(6);
|
43 |
|
44 | var src = '(' + function () {
|
45 | var xs = [ 1, 2, [ 3, 4 ] ];
|
46 | var ys = [ 5, 6 ];
|
47 | g([ xs, ys ]);
|
48 | } + ')()';
|
49 |
|
50 | var output = falafel(src, function (node) {
|
51 | if (node.type === 'ArrayExpression') {
|
52 | node.update('fn(' + node.source() + ')');
|
53 | }
|
54 | });
|
55 |
|
56 | t.test('inside test', function (q) {
|
57 | q.plan(2);
|
58 | q.ok(true);
|
59 |
|
60 | setTimeout(function () {
|
61 | q.ok(true);
|
62 | }, 100);
|
63 | });
|
64 |
|
65 | var arrays = [
|
66 | [ 3, 4 ],
|
67 | [ 1, 2, [ 3, 4 ] ],
|
68 | [ 5, 6 ],
|
69 | [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ],
|
70 | ];
|
71 |
|
72 | Function(['fn','g'], output)(
|
73 | function (xs) {
|
74 | t.same(arrays.shift(), xs);
|
75 | return xs;
|
76 | },
|
77 | function (xs) {
|
78 | t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
|
79 | }
|
80 | );
|
81 | });
|
82 |
|
83 | test('another', function (t) {
|
84 | t.plan(1);
|
85 | setTimeout(function () {
|
86 | t.ok(true);
|
87 | }, 50);
|
88 | });
|
89 | });
|