https://kotlinlang.org logo
Title
a

Asq

12/20/2021, 11:34 PM
I have a test that fails because the lhs of
shouldBe
is a
List
, and the rhs is a home-grown
Iterable
. This happens in
IterablEq.kt
(kotest 5.0.3) as
fun isValidIterable(it: Any): Boolean {
      return when (it) {
         is List<*>, is Set<*>, is Array<*>, is Collection<*> -> true
         else -> false
      }
   }
Could someone please help me understand why a custom implementation of
Iterable
should not be considered a valid iterable for the purposes of
kotest
?
j

Jim

12/20/2021, 11:37 PM
Just missed case? Seems valuable to me
s

sam

12/20/2021, 11:58 PM
Yeah we should add that - PR welcome @Asq
j

Jim

12/20/2021, 11:59 PM
While we're in there, do we have a similar assertion for sequence? Maybe flow?
s

sam

12/21/2021, 12:01 AM
should include whatever is feasible whilst bearing in mind that you might not want this to pass:
listOf(1,2,3) shouldBe myIterable(1,2,3)
or
listOf(1,2,3) shouldBe setOf(1,2,3)
I'd be inclined to say shouldBe should fail for those, and you use
shouldContainExactly
or whatever
shouldIterateEquals
j

Jim

12/21/2021, 12:02 AM
Agree 👌
a

Asq

12/21/2021, 1:52 AM
Respecting types is a sticky issue with iterable collections. The contract of
equals
(same hashcode) is a squishy thing to enforce, especially under inheritance.
shouldBe
as it is at present is largely ambiguous, as it tries really really hard to make things work. Is it trying too hard?
j

Jim

12/21/2021, 2:24 AM
I suppose you could chain should be same type and should iterate equals
a

Asq

12/21/2021, 5:11 PM
@sam I'm preparing a PR
🙌 1
👍🏻 1