UNPKG

2.1 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 var tc = function (rows) {
11 tt.same(rows.toString('utf8'), [
12 'TAP version 13',
13 '# nested array test',
14 'ok 1 should be equivalent',
15 'ok 2 should be equivalent',
16 'ok 3 should be equivalent',
17 'ok 4 should be equivalent',
18 'ok 5 should be equivalent',
19 '# inside test',
20 'ok 6 should be truthy',
21 'ok 7 should be truthy',
22 '# another',
23 'ok 8 should be truthy',
24 '',
25 '1..8',
26 '# tests 8',
27 '# pass 8',
28 '',
29 '# ok'
30 ].join('\n') + '\n');
31 };
32
33 test.createStream().pipe(concat(tc));
34
35 test('nested array test', function (t) {
36 t.plan(6);
37
38 var src = '(' + function () {
39 var xs = [ 1, 2, [ 3, 4 ] ];
40 var ys = [ 5, 6 ];
41 g([ xs, ys ]);
42 } + ')()';
43
44 var output = falafel(src, function (node) {
45 if (node.type === 'ArrayExpression') {
46 node.update('fn(' + node.source() + ')');
47 }
48 });
49
50 t.test('inside test', function (q) {
51 q.plan(2);
52 q.ok(true);
53
54 setTimeout(function () {
55 q.ok(true);
56 }, 100);
57 });
58
59 var arrays = [
60 [ 3, 4 ],
61 [ 1, 2, [ 3, 4 ] ],
62 [ 5, 6 ],
63 [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ],
64 ];
65
66 Function(['fn','g'], output)(
67 function (xs) {
68 t.same(arrays.shift(), xs);
69 return xs;
70 },
71 function (xs) {
72 t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
73 }
74 );
75 });
76
77 test('another', function (t) {
78 t.plan(1);
79 setTimeout(function () {
80 t.ok(true);
81 }, 50);
82 });
83});