https://kotlinlang.org logo
Title
s

Stefan

07/07/2021, 8:55 AM
Hi, is is possible with kotest to derive generators from data classes like with
scalacheck-shapeless
?
s

sam

07/07/2021, 10:43 AM
Yes there is bind.
s

Stefan

07/07/2021, 1:52 PM
yes, thank you! Does it work for nested structures as well?
internal class SomeTest : FreeSpec() {
  
    data class Inner(val t: String)
    data class Outer(val i: Inner)
    init {
      "String size" {
        checkAll<String, Outer>(Arb.string(), Arb.bind<Outer>()) { a, b ->
          a.length shouldBe b.i.t.length
        }
      }
    }
}
s

sam

07/07/2021, 2:50 PM
I don't think so, I'd have to check the code
s

Stefan

07/07/2021, 2:57 PM
still "Cannot infer generator for class Some$Outer; specify generators explicitly"
"String size" {
      checkAll<String, Outer>(Arb.string(), Arb.default()) { a, b ->
        a.length shouldBe b.i.t.length
      }
    }
s

sam

07/07/2021, 4:08 PM
You would need to pass in an arb manually, try this
"String size" {
      checkAll<String, Outer>(Arb.string(), Arb.bind<Outer>()) { a, b ->
        a.length shouldBe b.i.t.length
      }
    }
I think we should make it work without needing to specify anything, by defaulting to bind