Skip to content

Commit 7991377

Browse files
author
James Halliday
committed
passing array test
1 parent a5b83f2 commit 7991377

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

test/array.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
'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: true, name: 'should be equivalent' },
28+
'tests 5',
29+
'pass 5',
30+
'ok'
31+
]);
32+
});
33+
34+
test.stream.pipe(tc);
35+
36+
test('array', function (t) {
37+
t.plan(5);
38+
39+
var src = '(' + function () {
40+
var xs = [ 1, 2, [ 3, 4 ] ];
41+
var ys = [ 5, 6 ];
42+
g([ xs, ys ]);
43+
} + ')()';
44+
45+
var output = falafel(src, function (node) {
46+
if (node.type === 'ArrayExpression') {
47+
node.update('fn(' + node.source() + ')');
48+
}
49+
});
50+
51+
var arrays = [
52+
[ 3, 4 ],
53+
[ 1, 2, [ 3, 4 ] ],
54+
[ 5, 6 ],
55+
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ],
56+
];
57+
58+
Function(['fn','g'], output)(
59+
function (xs) {
60+
t.same(arrays.shift(), xs);
61+
return xs;
62+
},
63+
function (xs) {
64+
t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
65+
}
66+
);
67+
});
68+
});

0 commit comments

Comments
 (0)