1 | 'use strict';
|
2 |
|
3 | var falafel = require('falafel');
|
4 | var tape = require('../');
|
5 | var tap = require('tap');
|
6 | var concat = require('concat-stream');
|
7 |
|
8 | var stripFullStack = require('./common').stripFullStack;
|
9 |
|
10 | tap.test('array test', function (tt) {
|
11 | tt.plan(1);
|
12 |
|
13 | var test = tape.createHarness({ exit: false });
|
14 | var tc = function (rows) {
|
15 | tt.same(stripFullStack(rows.toString('utf8')), [
|
16 | 'TAP version 13',
|
17 | '# array',
|
18 | 'ok 1 should be deeply equivalent',
|
19 | 'ok 2 should be deeply equivalent',
|
20 | 'ok 3 should be deeply equivalent',
|
21 | 'ok 4 should be deeply equivalent',
|
22 | 'not ok 5 should be deeply equivalent',
|
23 | ' ---',
|
24 | ' operator: deepEqual',
|
25 | ' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]',
|
26 | ' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]',
|
27 | ' at: <anonymous> ($TEST/fail.js:$LINE:$COL)',
|
28 | ' stack: |-',
|
29 | ' Error: should be deeply equivalent',
|
30 | ' [... stack stripped ...]',
|
31 | ' at $TEST/fail.js:$LINE:$COL',
|
32 | ' at eval (eval at <anonymous> ($TEST/fail.js:$LINE:$COL))',
|
33 | ' at eval (eval at <anonymous> ($TEST/fail.js:$LINE:$COL))',
|
34 | ' at Test.<anonymous> ($TEST/fail.js:$LINE:$COL)',
|
35 | ' [... stack stripped ...]',
|
36 | ' ...',
|
37 | '',
|
38 | '1..5',
|
39 | '# tests 5',
|
40 | '# pass 4',
|
41 | '# fail 1',
|
42 | ''
|
43 | ]);
|
44 | };
|
45 |
|
46 | test.createStream().pipe(concat(tc));
|
47 |
|
48 | test('array', function (t) {
|
49 | t.plan(5);
|
50 |
|
51 | var src = '(' + function () {
|
52 | var xs = [1, 2, [3, 4]];
|
53 | var ys = [5, 6];
|
54 | g([xs, ys]);
|
55 | } + ')()';
|
56 |
|
57 | var output = falafel(src, function (node) {
|
58 | if (node.type === 'ArrayExpression') {
|
59 | node.update('fn(' + node.source() + ')');
|
60 | }
|
61 | });
|
62 |
|
63 | var arrays = [
|
64 | [3, 4],
|
65 | [1, 2, [3, 4]],
|
66 | [5, 6],
|
67 | [[1, 2, [3, 4]], [5, 6]]
|
68 | ];
|
69 |
|
70 | Function(['fn', 'g'], output)(
|
71 | function (xs) {
|
72 | t.same(arrays.shift(), xs);
|
73 | return xs;
|
74 | },
|
75 | function (xs) {
|
76 | t.same(xs, [[1, 2, [3, 4444]], [5, 6]]);
|
77 | }
|
78 | );
|
79 | });
|
80 | });
|