UNPKG

825 BJavaScriptView Raw
1const test = require('./config').test
2const { CPS } = require('..')
3
4const cpsFun = cb => cb(42)
5const cpsWrapped = CPS(cpsFun)
6
7
8test('does not mutate source', t => {
9 let obj = {}
10 CPS(obj)
11 t.deepEqual(obj, {})
12})
13
14test('map method works correctly', t => {
15 const cpsNew = cpsWrapped.map(y => y + 1)
16 cpsNew(t.cis(43))
17})
18
19test('map is provided on target as well', t => {
20 cpsWrapped
21 .map(z => z + 2)
22 .map(z => z - 1)
23 (t.cis(43))
24})
25
26test('provide chain method on CPS functions', t => {
27 CPS(cpsFun).chain(y => cb => cb(y + 1))
28 (t.cis(43))
29})
30test('chain is provided on target as well', t => {
31 cpsWrapped
32 .chain(z => cb => cb(z + 2))
33 .chain(z => cb => cb(z - 1))
34 (t.cis(43))
35})
36
37test('function on CPS(fn) is delegated to fn', t => {
38 const cpsFun = cb => cb(42)
39 t.is(
40 CPS(cpsFun)(x => x + 1),
41 43
42 )
43})