|
| 1 | +const test = require('./config') |
| 2 | +const { mapSpread } = require('..') |
| 3 | + |
| 4 | +test('mapSpread transforms output 1-tuples to m-tuples', t => { |
| 5 | + const cpsFun = cb => cb(42) |
| 6 | + mapSpread(x => [])(cpsFun)(t.cis()) |
| 7 | + mapSpread(x => [x*2])(cpsFun)(t.cis(84)) |
| 8 | + mapSpread(x => [x,x*2])(cpsFun)(t.cis(42,84)) |
| 9 | + mapSpread(x => [x,x*2,5])(cpsFun)(t.cis(42,84,5)) |
| 10 | +}) |
| 11 | + |
| 12 | +test('mapSpread transforms output 2-tuples to m-tuples', t => { |
| 13 | + const cpsFun = cb => cb(42, 24) |
| 14 | + mapSpread((a,b)=>[])(cpsFun)(t.cis()) |
| 15 | + mapSpread((a,b)=>[a-b])(cpsFun)(t.cis(18)) |
| 16 | + mapSpread((a,b)=>[a,a-b,b,1])(cpsFun)(t.cis(42,18,24,1)) |
| 17 | +}) |
| 18 | + |
| 19 | +test('mapSpread over single function with no arguments', t => { |
| 20 | + const cpsFun = cb => cb() |
| 21 | + mapSpread(() => [])(cpsFun)(t.cis()) |
| 22 | + mapSpread(() => [30])(cpsFun)(t.cis(30)) |
| 23 | +}) |
| 24 | + |
| 25 | +test('mapSpread preserves outputs for missing transforms', t => { |
| 26 | + const cpsFun = (cb1, cb2) => {cb1(42); cb2(23)} |
| 27 | + mapSpread(x => [x*2,1,4])(cpsFun)(_ => null, t.cis(23)) |
| 28 | +}) |
| 29 | + |
| 30 | +test('mapSpread over multiple functions', t => { |
| 31 | + t.plan(4) |
| 32 | + const cpsFun = (cb1, cb2) => {cb1(42); cb2(23)} |
| 33 | + mapSpread(x => [x/2], x => [x*2])(cpsFun)(t.cis(21), t.cis(46)) |
| 34 | + mapSpread(x => [x/2,x], x => [x*2,-x])(cpsFun)(t.cis(21,42), t.cis(46,-23)) |
| 35 | +}) |
| 36 | + |
| 37 | +test('mapSpread over more functions than callbacks, the extra functions are ignored', t => { |
| 38 | + const cpsFun = cb => cb(42) |
| 39 | + mapSpread(x => [x*2], x => [x+10])(cpsFun)(t.cis(84)) |
| 40 | +}) |
| 41 | + |
| 42 | +test('mapSpread transforms tuples via arrays', t => { |
| 43 | + const F = cb => cb(1,2) |
| 44 | + mapSpread((...arr) => arr.map(a => a + 1))(F)(t.cDeepEqual(2,3)) |
| 45 | +}) |
0 commit comments