-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
96 lines (90 loc) · 1.99 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const test = require('tape');
const fromIter = require('callbag-from-iter');
const map = require('callbag-map');
const filter = require('callbag-filter');
const forEach = require('callbag-for-each');
const pipe = require('./readme');
test('it calls first-order functions in sequence LTR', (t) => {
t.plan(1);
const res = pipe(
2, // 2
x => x * 10, // 20
x => x - 3, // 17
x => x + 5 // 22
);
t.equals(res, 22);
});
test('it calls first-order functions in a nested pipe', (t) => {
t.plan(1);
const res = pipe(
2, // 2
s => pipe(s,
x => x * 10, // 20
x => x - 3 // 17
),
x => x + 5 // 22
);
t.equals(res, 22);
});
test('it calls higher-order callbacks in sequence LTR', (t) => {
t.plan(2);
const res = pipe(
cb => cb(2), // 2
prev => cb => prev(x => cb(x * 10)), // 20
prev => cb => prev(x => cb(x - 3)), // 17
prev => cb => prev(x => cb(x + 5)) // 22
);
t.equals(typeof res, 'function');
res(x => {
t.equals(x, 22);
t.end();
});
});
test('it can be nested', (t) => {
t.plan(2);
const res = pipe(
cb => cb(2), // 2
s => pipe(s,
prev => cb => prev(x => cb(x * 10)), // 20
prev => cb => prev(x => cb(x - 3)) // 17
),
prev => cb => prev(x => cb(x + 5)) // 22
);
t.equals(typeof res, 'function');
res(x => {
t.equals(x, 22);
t.end();
});
});
test('it works with common callbag utilities', (t) => {
t.plan(2);
const expected = [1, 3];
pipe(
fromIter([10, 20, 30, 40]),
map(x => x / 10),
filter(x => x % 2),
forEach(x => {
t.equals(x, expected.shift());
if (expected.length === 0) {
t.end();
}
})
);
});
test('it can be nested with callbag utilities', (t) => {
t.plan(2);
const expected = [1, 3];
pipe(
fromIter([10, 20, 30, 40]),
s => pipe(s,
map(x => x / 10),
filter(x => x % 2)
),
forEach(x => {
t.equals(x, expected.shift());
if (expected.length === 0) {
t.end();
}
})
);
});