UNPKG

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