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

dimsuz

08/06/2021, 3:38 PM
what's the best way to generate "whitespace or empty" strings using
Arb
?
s

sam

08/06/2021, 3:50 PM
Could quickly write one, would be a good PR actually
d

dimsuz

08/06/2021, 3:53 PM
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

sam

08/06/2021, 3:56 PM
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

dimsuz

08/06/2021, 4:07 PM
oh, nice, thank you. I can send PR a bit later if needed. Would
Arb.whitespace()
be a good name?
s

sam

08/06/2021, 4:08 PM
yep
l

LeoColman

08/06/2021, 6:43 PM
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

sam

08/06/2021, 6:50 PM
I think " " is whitespace
not sure about empty string
l

LeoColman

08/06/2021, 6:51 PM
Kotlin has String.isBlank()
which returns true for empty string
s

sam

08/06/2021, 6:51 PM
ahh so that's a better term
Arb.blanks() ?
l

LeoColman

08/06/2021, 6:52 PM
(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

sam

08/06/2021, 6:56 PM
yeah if we don't we can add the blanks one. I think that's a good suggestion.
d

dimsuz

08/06/2021, 10:31 PM
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

sam

08/06/2021, 10:32 PM
I think the latter, isBlank should be true
👍 1
4 Views