-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test_group.res
36 lines (30 loc) · 953 Bytes
/
Test_group.res
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
open Test
module S = ReStream
testAsync("group", (done) => {
let arr = Belt.Array.range(1, 10)
let result = [
Belt.Array.range(1, 3) -> Belt.Array.map(v => "#" ++ Int.toString(v)),
Belt.Array.range(4, 6) -> Belt.Array.map(v => "#" ++ Int.toString(v)),
Belt.Array.range(7, 9) -> Belt.Array.map(v => "#" ++ Int.toString(v)),
Belt.Array.range(10, 10) -> Belt.Array.map(v => "#" ++ Int.toString(v)),
]
let fail1 = ref(false)
S.fromArray(arr)
-> ReStream_Utils.checkStep(() => fail1 := true)
-> S.asyncMap((v, cb) => {
let newValue = "#" ++ Int.toString(v)
newValue -> Test_Utils.rndDelay(~min=10, ~max=50, cb)
})
-> S.group(3)
// -> S.log
-> S.collect(res => {
switch res {
| Ok(arr) => {
Assert.boolEqual(~message="must not call Pull before receiving payload", fail1.contents, false)
Assert.arrayOfArraysDeepEqual(~message="result matches", arr, result)
done()
}
| Error(_) => fail()
}
})
})