what's the best way to generate "whitespace or emp...
# kotest
d
what's the best way to generate "whitespace or empty" strings using
Arb
?
s
Could quickly write one, would be a good PR actually
d
What should it be based on? Some
Arb<Codepoint>
which uses the same as the
CharSet.WHITESPACE
(saw it in sources, but it's private). Ah, but that would need an empty case which is not a Codepoint
s
if you want something that has more white space than just 1
arbitrary { List(it.random.nextInt(10)).joinToString(" ") }
or something
(not tested in ide)
d
oh, nice, thank you. I can send PR a bit later if needed. Would
Arb.whitespace()
be a good name?
s
yep
l
Is an empty string a whitespace tho?
Maybe create two versions, Arb.whitespace() and Arb.whitespaceOrEmpty()
that way the suggestions inside intellij will be very intuitive
what do you guys think?
s
I think " " is whitespace
not sure about empty string
l
Kotlin has String.isBlank()
which returns true for empty string
s
ahh so that's a better term
Arb.blanks() ?
l
(for empty and for whitespace)
"*A String is blank when either its length is zero or it contains only whitespace characters"*
I'm also for to just have an extension on Arb<String>: arb.orEmpty(). I don't know if we have this already or somethingn similar
s
yeah if we don't we can add the blanks one. I think that's a good suggestion.
d
Also I'm not sure about this: should this also produce "\t" characters? nbsp characters too? maybe anything for which Char.isWhitespace() returns true? or only ascii spaces? Or maybe kotlin's
isBlank()
could be used as a guideline, i.e.
Arb.blanks().map { it.isBlank() } == [true]
s
I think the latter, isBlank should be true
👍 1