Initial commit
[yaffs-website] / node_modules / concat-map / test / map.js
1 var concatMap = require('../');
2 var test = require('tape');
3
4 test('empty or not', function (t) {
5     var xs = [ 1, 2, 3, 4, 5, 6 ];
6     var ixes = [];
7     var ys = concatMap(xs, function (x, ix) {
8         ixes.push(ix);
9         return x % 2 ? [ x - 0.1, x, x + 0.1 ] : [];
10     });
11     t.same(ys, [ 0.9, 1, 1.1, 2.9, 3, 3.1, 4.9, 5, 5.1 ]);
12     t.same(ixes, [ 0, 1, 2, 3, 4, 5 ]);
13     t.end();
14 });
15
16 test('always something', function (t) {
17     var xs = [ 'a', 'b', 'c', 'd' ];
18     var ys = concatMap(xs, function (x) {
19         return x === 'b' ? [ 'B', 'B', 'B' ] : [ x ];
20     });
21     t.same(ys, [ 'a', 'B', 'B', 'B', 'c', 'd' ]);
22     t.end();
23 });
24
25 test('scalars', function (t) {
26     var xs = [ 'a', 'b', 'c', 'd' ];
27     var ys = concatMap(xs, function (x) {
28         return x === 'b' ? [ 'B', 'B', 'B' ] : x;
29     });
30     t.same(ys, [ 'a', 'B', 'B', 'B', 'c', 'd' ]);
31     t.end();
32 });
33
34 test('undefs', function (t) {
35     var xs = [ 'a', 'b', 'c', 'd' ];
36     var ys = concatMap(xs, function () {});
37     t.same(ys, [ undefined, undefined, undefined, undefined ]);
38     t.end();
39 });