source: trip-planner-front/node_modules/concat-map/test/map.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.0 KB
RevLine 
[6a3a178]1var concatMap = require('../');
2var test = require('tape');
3
4test('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
16test('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
25test('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
34test('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});
Note: See TracBrowser for help on using the repository browser.