forked from fsprojects/FSharp.Control.TaskSeq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskSeq.Singleton.Tests.fs
More file actions
96 lines (81 loc) · 3.02 KB
/
TaskSeq.Singleton.Tests.fs
File metadata and controls
96 lines (81 loc) · 3.02 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
module TaskSeq.Tests.Singleton
open System.Threading.Tasks
open Xunit
open FsUnit.Xunit
open FsToolkit.ErrorHandling
open FSharp.Control
module EmptySeq =
[<Theory; ClassData(typeof<TestEmptyVariants>)>]
let ``TaskSeq-singleton with empty has length one`` variant =
taskSeq {
yield! TaskSeq.singleton 10
yield! Gen.getEmptyVariant variant
}
|> TaskSeq.exactlyOne
|> Task.map (should equal 10)
module Other =
[<Fact>]
let ``TaskSeq-singleton creates a sequence of one`` () =
TaskSeq.singleton 42
|> TaskSeq.exactlyOne
|> Task.map (should equal 42)
[<Fact>]
let ``TaskSeq-singleton can be yielded multiple times`` () =
let singleton = TaskSeq.singleton 42
taskSeq {
yield! singleton
yield! singleton
yield! singleton
yield! singleton
}
|> TaskSeq.toList
|> should equal [ 42; 42; 42; 42 ]
[<Fact>]
let ``TaskSeq-singleton with isEmpty`` () =
TaskSeq.singleton 42
|> TaskSeq.isEmpty
|> Task.map (should be False)
[<Fact>]
let ``TaskSeq-singleton with append`` () =
TaskSeq.singleton 42
|> TaskSeq.append (TaskSeq.singleton 42)
|> TaskSeq.toList
|> should equal [ 42; 42 ]
[<Theory; ClassData(typeof<TestImmTaskSeq>)>]
let ``TaskSeq-singleton with collect`` variant =
Gen.getSeqImmutable variant
|> TaskSeq.collect TaskSeq.singleton
|> verify1To10
[<Fact>]
let ``TaskSeq-singleton does not throw when getting Current before MoveNext`` () = task {
let enumerator = (TaskSeq.singleton 42).GetAsyncEnumerator()
let defaultValue = enumerator.Current // should return the default value for int
defaultValue |> should equal 0
}
[<Fact>]
let ``TaskSeq-singleton does not throw when getting Current after last MoveNext`` () = task {
let enumerator = (TaskSeq.singleton 42).GetAsyncEnumerator()
let! isNext = enumerator.MoveNextAsync()
isNext |> should be True
let value = enumerator.Current // the first and only value
value |> should equal 42
// move past the end
let! isNext = enumerator.MoveNextAsync()
isNext |> should be False
let defaultValue = enumerator.Current // should return the default value for int
defaultValue |> should equal 0
}
[<Fact>]
let ``TaskSeq-singleton multiple MoveNext is fine`` () = task {
let enumerator = (TaskSeq.singleton 42).GetAsyncEnumerator()
let! isNext = enumerator.MoveNextAsync()
isNext |> should be True
let! _ = enumerator.MoveNextAsync()
let! _ = enumerator.MoveNextAsync()
let! _ = enumerator.MoveNextAsync()
let! isNext = enumerator.MoveNextAsync()
isNext |> should be False
// should return the default value for int after moving past the end
let defaultValue = enumerator.Current
defaultValue |> should equal 0
}