1 | const test = require('tape');
|
2 | const { reduceMap } = require('./iterable');
|
3 |
|
4 | test('reduceMap()', assert => {
|
5 | const createMap = () =>
|
6 | new Map([
|
7 | [() => false, () => false],
|
8 | [(first, second) => second === 'b', (third, fourth) => fourth],
|
9 | ]);
|
10 |
|
11 | {
|
12 | const actual = reduceMap({
|
13 | map: createMap(),
|
14 | keyArguments: ['a', 'b'],
|
15 | valueArguments: ['c', 'd'],
|
16 | });
|
17 | const expected = 'd';
|
18 | const message =
|
19 | 'returns the output of the first value function where the key function is truthy';
|
20 |
|
21 | assert.equal(actual, expected, message);
|
22 | }
|
23 | {
|
24 | const actual = reduceMap({
|
25 | map: createMap(),
|
26 | fallback: 'foo',
|
27 | });
|
28 | const expected = 'foo';
|
29 | const message = 'returns the fallback value if there are no matches';
|
30 |
|
31 | assert.equal(actual, expected, message);
|
32 | }
|
33 | {
|
34 | const actual = reduceMap({
|
35 | map: createMap(),
|
36 | valueArguments: ['c', 'd'],
|
37 | fallback: (first, second) => second,
|
38 | });
|
39 | const expected = 'd';
|
40 | const message =
|
41 | 'supports fallback as a function, with the functionArgs supplied';
|
42 |
|
43 | assert.equal(actual, expected, message);
|
44 | }
|
45 | assert.end();
|
46 | });
|