Skip to content

Commit

Permalink
Support ValueTask and Async bindings in testTask (#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
farlee2121 committed Mar 15, 2024
1 parent 7e211cf commit c2e3e2d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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
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

0 comments on commit c2e3e2d

Please sign in to comment.