-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7987075
commit 063e385
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/FSharp.Control.TaskSeq.Test/TaskSeq.Singleton.Tests.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters