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