Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Expecto.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,22 @@ let taskTests =
testTask "inner skip" {
skiptest "skipped"
}
testTask "can let! bind ValueTask<T>" {
let expected = 5
let valueTask = ValueTask.FromResult(expected)
let! actual = valueTask
Expect.equal expected actual "should be able to let! bind ValueTask<T>"
}
testTask "can do! bind ValueTask" {
let valueTask = ValueTask.CompletedTask
do! valueTask
}
testTask "can let! bind Async<T>" {
let expected = 5
let asyncValue = async.Return(expected)
let! actual = asyncValue
Expect.equal expected actual "should be able to let! bind ValueTask<T>"
}
]
]

Expand Down
7 changes: 7 additions & 0 deletions Expecto/Expecto.fs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ module Tests =
| Focused -> ftestCaseTask name a
| Pending -> ptestCaseTask name a

[<AutoOpen>]
module TestTaskExtensions =
type TestTaskBuilder with
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding these overloads as extensions helps the compiler know to prioritize the original Task overload, which prevents breakage in existing code that may have implicitly typed an expression based on Bind originally only taking variations of Task.

member inline __.Bind(p1:ValueTask<'a>, p2:'a->_) = task.Bind(p1, p2)
member inline __.Bind(p1:ValueTask, p2:unit->_) = task.Bind(p1, p2)
member inline __.Bind(p1:Async<'a>, p2:'a->_) = task.Bind(p1, p2)

/// Builds a task test case
let inline testTask name =
TestTaskBuilder (name, Normal)
Expand Down