Skip to content

Commit

Permalink
Add some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abelbraaksma committed Dec 19, 2022
1 parent b0abcee commit 34d029d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/FSharp.Control.TaskSeq.Test/TaskSeq.Cast.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ let validateSequence ts =

module EmptySeq =
[<Fact>]
let ``Null source is invalid`` () = assertNullArg <| fun () -> TaskSeq.box null
let ``Null source is invalid`` () =
assertNullArg <| fun () -> TaskSeq.box null
assertNullArg <| fun () -> TaskSeq.unbox null
assertNullArg <| fun () -> TaskSeq.cast null

[<Theory; ClassData(typeof<TestEmptyVariants>)>]
let ``TaskSeq-box empty`` variant = Gen.getEmptyVariant variant |> TaskSeq.box |> verifyEmpty
Expand Down
31 changes: 30 additions & 1 deletion src/FSharp.Control.TaskSeq.Test/TaskSeq.Singleton.Tests.fs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
module TaskSeq.Tests.Singleton

open System.Threading.Tasks
open Xunit
open FsUnit.Xunit
open FsToolkit.ErrorHandling

open FSharp.Control

//
// TaskSeq.singleton
//

module EmptySeq =

[<Theory; ClassData(typeof<TestEmptyVariants>)>]
Expand All @@ -18,13 +21,39 @@ module EmptySeq =
|> TaskSeq.exactlyOne
|> Task.map (should equal 10)

module SideEffects =
[<Fact>]
let ``TaskSeq-singleton with a mutable value`` () =
let mutable x = 0
let ts = TaskSeq.singleton x
x <- x + 1

// mutable value is dereferenced when passed to a function
ts |> TaskSeq.exactlyOne |> Task.map (should equal 0)

[<Fact>]
let ``TaskSeq-singleton with a ref cell`` () =
let x = ref 0
let ts = TaskSeq.singleton x
x.Value <- x.Value + 1

ts
|> TaskSeq.exactlyOne
|> Task.map (fun x -> x.Value |> should equal 1)

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 with null as value`` () =
TaskSeq.singleton null
|> TaskSeq.exactlyOne
|> Task.map (should be Null)

[<Fact>]
let ``TaskSeq-singleton can be yielded multiple times`` () =
let singleton = TaskSeq.singleton 42
Expand Down

0 comments on commit 34d029d

Please sign in to comment.