https://kotlinlang.org logo
Title
e

Emil Kantis

04/17/2023, 8:49 PM
inline infix fun <reified T> (() -> T).shouldReturn(expected: T) = this() shouldBe expected
worth adding?
Could, of course, be a bit more elaborate and include a tailored failure message etc..
m

mitch

04/20/2023, 9:48 AM
hmmm what’s the use case? I wonder if it can be written as this one instead?
run { ... } shouldBe expected
e

Emil Kantis

04/20/2023, 5:26 PM
Hmm, I had a case where I wanted to test a list of
Pair<Int, () -> String>
using something like
items.forOne {
  it.first shouldBe 5
  it.second shouldReturn "hello"
}
I made some custom matchers later on so it's a non-issue for me now.. anyway.. you're right, I could've done this. 🙂
items.forOne {
  it.first shouldBe 5
  run(it.second) shouldBe "hello"
}
or just
it.second() shouldBe "hello"