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

Adam S

03/16/2022, 5:31 PM
would it be useful/cool to have an arb that generates values from a Kotlinx Serialization KSerializer? It's a bit of a nicer, more automatic way of creating binds, without having to define Arbs for all the fields in a target class.
e

Emil Kantis

03/16/2022, 6:29 PM
Iirc there's already automatic arbs for data classes (containing primitives or other data classes). How would you use the serializer?
a

Adam S

03/16/2022, 6:35 PM
ah, okay, I didn't see any automatic data class arbs. Do you know where it is? What do you mean, 'use the serializer'? At the moment I made an extension function on KSerializer that returns an arb
Copy code
val personArb = Person.serializer().arb()
I meant - How does the extension function work? Do you use the serial descriptor somehow to generate the class? 🤔
a

Adam S

03/16/2022, 7:02 PM
ahhh yes, here's the code (I forgot to attach it). It's more of a POC at the mo. I think it could be made more useful, like making it shrinkable
ah okay, yes this is similar to jvmbind.kt. Except it works on any
@Serializable
class, and is multiplatform.
e

Emil Kantis

03/16/2022, 7:10 PM
Yeah, the fact that it is available for multiplatform is awesome imo. Biggest drawback is perhaps that it wouldn’t generate edge cases for underlying arbs?
a

Adam S

03/16/2022, 7:14 PM
as written, it doesn't do anything clever. No shrinks, no edgecases. I think it would be possible though. Instead of directly generating values from arbs, there would have to be something intermediate to make ArbDecoder get values from edgecases/shrinks
3 Views