1 | const test = require('./config').test
|
2 | const { CPS } = require('..')
|
3 |
|
4 | const cpsFun = cb => cb(42)
|
5 | const cpsWrapped = CPS(cpsFun)
|
6 |
|
7 |
|
8 | test('does not mutate source', t => {
|
9 | let obj = {}
|
10 | CPS(obj)
|
11 | t.deepEqual(obj, {})
|
12 | })
|
13 |
|
14 | test('map method works correctly', t => {
|
15 | const cpsNew = cpsWrapped.map(y => y + 1)
|
16 | cpsNew(t.cis(43))
|
17 | })
|
18 |
|
19 | test('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 |
|
26 | test('provide chain method on CPS functions', t => {
|
27 | CPS(cpsFun).chain(y => cb => cb(y + 1))
|
28 | (t.cis(43))
|
29 | })
|
30 | test('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 |
|
37 | test('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 | })
|