Skip to content

Commit

Permalink
kotest shouldBeSuccess() returning value
Browse files Browse the repository at this point in the history
  • Loading branch information
dkandalov committed Sep 22, 2023
1 parent a7a2edb commit f6c5622
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ fun beSuccess(): Matcher<Result<*, *>> = object : Matcher<Result<*, *>> {
}

@OptIn(ExperimentalContracts::class)
fun <T> Result<T, *>.shouldBeSuccess() {
fun <T> Result<T, *>.shouldBeSuccess(): T {
contract {
returns() implies (this@shouldBeSuccess is Success<*>)
returns() implies (this@shouldBeSuccess is Success<T>)
}
this should beSuccess()
return (this as Success).value
}

infix fun <T> Result<T, *>.shouldBeSuccess(block: (T) -> Unit) {
this.shouldBeSuccess()
block((this as Success<T>).value)
block(this.shouldBeSuccess())
}

infix fun <T> Result<T, *>.shouldBeSuccess(value: T) = this should beSuccess(value)
Expand Down

0 comments on commit f6c5622

Please sign in to comment.