-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathTaskSeq.Concat.Tests.fs
More file actions
110 lines (95 loc) · 3.34 KB
/
TaskSeq.Concat.Tests.fs
File metadata and controls
110 lines (95 loc) · 3.34 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
module TaskSeq.Tests.Concat
open System.Collections.Generic
open Xunit
open FsUnit.Xunit
open FSharp.Control
//
// TaskSeq.concat
//
let validateSequence ts =
ts
|> TaskSeq.toListAsync
|> Task.map (List.map string)
|> Task.map (String.concat "")
|> Task.map (should equal "123456789101234567891012345678910")
module EmptySeq =
[<Fact>]
let ``Null source is invalid`` () = assertNullArg <| fun () -> TaskSeq.concat null
[<Theory; ClassData(typeof<TestEmptyVariants>)>]
let ``TaskSeq-concat with empty sequences`` variant =
taskSeq {
yield Gen.getEmptyVariant variant // not yield-bang!
yield Gen.getEmptyVariant variant
yield Gen.getEmptyVariant variant
}
|> TaskSeq.concat
|> verifyEmpty
[<Theory; ClassData(typeof<TestEmptyVariants>)>]
let ``TaskSeq-concat with top sequence empty`` variant =
Gen.getEmptyVariant variant
|> TaskSeq.box
|> TaskSeq.cast<IAsyncEnumerable<int>> // casting an int to an enumerable, LOL!
|> TaskSeq.concat
|> verifyEmpty
module Immutable =
[<Theory; ClassData(typeof<TestImmTaskSeq>)>]
let ``TaskSeq-concat with three sequences of sequences`` variant =
taskSeq {
yield Gen.getSeqImmutable variant // not yield-bang!
yield Gen.getSeqImmutable variant
yield Gen.getSeqImmutable variant
}
|> TaskSeq.concat
|> validateSequence
[<Theory; ClassData(typeof<TestImmTaskSeq>)>]
let ``TaskSeq-concat with three sequences of sequences and few empties`` variant =
taskSeq {
yield TaskSeq.empty
yield Gen.getSeqImmutable variant // not yield-bang!
yield TaskSeq.empty
yield TaskSeq.empty
yield Gen.getSeqImmutable variant
yield TaskSeq.empty
yield Gen.getSeqImmutable variant
yield TaskSeq.empty
yield TaskSeq.empty
yield TaskSeq.empty
yield TaskSeq.empty
}
|> TaskSeq.concat
|> validateSequence
module SideEffect =
[<Theory; ClassData(typeof<TestImmTaskSeq>)>]
let ``TaskSeq-concat consumes until the end, including side-effects`` variant =
let mutable i = 0
taskSeq {
yield Gen.getSeqImmutable variant // not yield-bang!
yield Gen.getSeqImmutable variant
yield taskSeq {
yield! [ 1..10 ]
i <- i + 1
}
}
|> TaskSeq.concat
|> validateSequence
|> Task.map (fun () -> i |> should equal 1)
[<Theory; ClassData(typeof<TestImmTaskSeq>)>]
let ``TaskSeq-concat consumes side effects in empty sequences`` variant =
let mutable i = 0
taskSeq {
yield taskSeq { do i <- i + 1 }
yield Gen.getSeqImmutable variant // not yield-bang!
yield TaskSeq.empty
yield taskSeq { do i <- i + 1 }
yield Gen.getSeqImmutable variant
yield TaskSeq.empty
yield Gen.getSeqImmutable variant
yield TaskSeq.empty
yield TaskSeq.empty
yield TaskSeq.empty
yield TaskSeq.empty
yield taskSeq { do i <- i + 1 }
}
|> TaskSeq.concat
|> validateSequence
|> Task.map (fun () -> i |> should equal 3)