Skip to content

Commit

Permalink
completing coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriz committed Jun 8, 2019
1 parent c21f7d5 commit 41a4ead
Showing 1 changed file with 9 additions and 64 deletions.
73 changes: 9 additions & 64 deletions test/ap.test.js
Expand Up @@ -48,7 +48,6 @@ test('ap of 2-callback-CPS over single function is passing 2nd callback unchange
cpsNew(notCalled, t.cis('error'))
})


test('ap only applies to callbacks with output', t => {
const cpsFun = (cb, onErr) => {onErr('error')}
const cpsNew = ap(
Expand All @@ -61,66 +60,12 @@ test('ap only applies to callbacks with output', t => {
t.cis('logs error'))
})


// test('ap over pair of functions applies to outputs from separate callbacks', t => {
// const cpsFun = (cb, onErr) => {cb(1); onErr('error')}
// const cpsNew = ap(
// cb => {cb(x => x + 1)},
// onErr => {onErr(err => 'logs ' + err)}
// )(cpsFun)
// t.plan(2)
// cpsNew(t.cis(11), t.cis('logs error'))
// })


// test('chain over multiple functions with the same output twice', t => {
// // 42 and 10.5 passed respectively into the first and second callback
// const cpsFun = (cb1, cb2) => cb1(42) + cb2(10.5)
// // both output are transformed into the same result
// const cpsNew = chain(
// x => cb => cb(x/2),
// x => cb => cb(x*2)
// )(cpsFun)
// t.plan(2)
// cpsNew(t.cis(21))
// })

// test('chain over multiple functions merges the outputs', t => {
// // one output for each callback
// let called = false
// const cpsFun = (cb1, cb2) => { cb1(2); cb2(5) }
// const newCps = chain(
// // output 42 is passed here
// x => cb => cb(x/2),
// // output 21 is passed here
// x => cb => cb(x*2)
// )(cpsFun)

// // called twice - with 21 and 42 as outputs
// t.plan(2)
// newCps(res => {
// t.cis(called ? 10 : 1)(res)
// called = true
// })
// })

// test('ap over transforming functions with multiple callbacks merge by index', t => {
// const cpsFun = (cb1, cb2) => { cb1(8); cb2(2) }
// const newCps = ap(
// (c1, c2) => {c1(x => x/2); c2(x => x*2)},
// )(cpsFun)
// // each callback is called twice
// t.plan(4)
// newCps(
// // 4 = 8/2 = 2*2 is passed twice, once from each of c1 and cb1
// t.cis(4),
// // 8 = 8 = 2*4 is passed twice, once from each of c2 and cb2
// t.cis(8)
// )
// })

// test('chain over fewer fns than cbs should preserve the extra outputs', t => {
// t.plan(2)
// const cpsFun = (cb1, cbb) => { cb1(0); cbb(2) }
// chain(x => cb => cb(x + 1))(cpsFun)(t.cis(1), t.cis(2))
// })
test('works when function is returned earlier than value', t => {
let callback = () => {}
// give control to f
const cpsFun = cb => { callback = cb }
const transformer = cb => cb(x => x + 1)
ap(transformer)(cpsFun)(t.cis(6))
// ensure call after transformer
callback(5)
})

0 comments on commit 41a4ead

Please sign in to comment.