https://kotlinlang.org logo
Title
d

dave08

05/18/2021, 1:31 PM
What's the best way to generate a base64 token with Arb?
s

sam

05/18/2021, 1:31 PM
You just want a random base 64 string ?
d

dave08

05/18/2021, 1:31 PM
Yeah, with a certain range of lengths
I don't see a base64 codepoint, which I would assume to be what I need?
s

sam

05/18/2021, 1:33 PM
Yes was just typing that
you need a base 64 codepoint arb (please contribute?) and then feed that into the string arb
Arb.string(0, 128, Arb.base64())
d

dave08

05/18/2021, 1:42 PM
I guess the naive implementation would be:
fun Arb.Companion.base64(): Arb<Codepoint> =
    Arb.element((('a'..'z') + ('A'..'Z') + ('0'..'9') + '+' + '/').toList()).map { Codepoint(it.code) }
But that ignores the
=
padding...
It doesn't really matter in my case for now... but a real implementation wouldn't just be codepoints.
s

sam

05/18/2021, 1:44 PM
yeah it would be codepoints + padding
still feel free to contribute one 🙂
d

dave08

05/18/2021, 1:52 PM
If I have a chance to make a more complete Arb for this, I surely will!