https://kotlinlang.org logo
#kotest
Title
# kotest
m

Michael Strasser

10/20/2021, 11:46 AM
Is it possible to compare function types? Given something like:
Copy code
typealias Matcher = (String) -> Boolean
data class Thing(matcher: Matcher)
This fails:
Copy code
it("compares values of function types") {
    val testThing = Thing({ it.startsWith("test") })
    testThing.matcher shouldBe { it.startsWith("test") }
}
with messages like:
Copy code
expected:<(kotlin.String) -> kotlin.Boolean> but was:<(kotlin.String) -> kotlin.Boolean>
s

sam

10/20/2021, 11:55 AM
It can't compare the code inside the functions as that's not made available so it's comparing by reference here
m

Michael Strasser

10/20/2021, 11:56 AM
Thanks! That’s what I thought.
9 Views