Sandymcp
10/25/2021, 3:11 PMpackage sse
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import java.io.BufferedReader
import java.io.StringReader
data class Case<G, W>(val given: G, val want: W)
class SseReaderKoTest : FunSpec({
context("read tag and payload test") {
withData(
mapOf(
"empty marks end of message" to Case("\n", "" to ""),
"event and payload" to Case("event: surprise\n", "event" to "surprise"),
"data and payload" to Case("data: surprise\n", "data" to "surprise"),
"id and payload" to Case("id: surprise\n", "id" to "surprise"),
"comment" to Case(": surprise\n", ":" to ""),
"blank comment" to Case(":\n", ":" to ""),
)
) { (given, want) ->
readTagAndPayload(BufferedReader(StringReader(given))) shouldBe want
}
}
})
dave08
10/25/2021, 3:21 PMSandymcp
10/25/2021, 3:22 PMdave08
10/25/2021, 3:23 PMSandymcp
10/25/2021, 3:24 PMwithData
methods it looks like I should be using
@io.kotest.common.ExperimentalKotest @kotlin.jvm.JvmName public suspend fun <T : kotlin.Any> io.kotest.core.test.TestContext.withData(data: kotlin.collections.Map<kotlin.String, T>, test: suspend io.kotest.core.test.TestContext.(T) -> kotlin.Unit): kotlin.Unit { /* compiled code */ }
dave08
10/25/2021, 3:25 PMSandymcp
10/25/2021, 3:26 PMexhaustive
looked like a simple change and improvement for namingdave08
10/25/2021, 3:30 PMSandymcp
10/25/2021, 3:37 PM@Test
fun t()
mapOf().forEach {
}
}
and just use Kotlin test - which was my starting point, and worked perfectly. But then one of my colleagues pointed kotest out. The only reason for using Kotest in the first place is to allow all the iterations to be run and get better naming. If I can’t get that, then there’s little point using all the other even clunkier mechanisms. There’s obviously some incantation I’m missing somewheredave08
10/25/2021, 3:40 PMmapOf(
"empty marks end of message" to Case(, "\n", "" to ""),
"event and payload" to Case("event: surprise\n", "event" to "surprise"),
"data and payload" to Case("data: surprise\n", "data" to "surprise"),
"id and payload" to Case("id: surprise\n", "id" to "surprise"),
"comment" to Case(": surprise\n", ":" to ""),
"blank comment" to Case(":\n", ":" to ""),
).forEach { (given, want) ->
it(given) {
readTagAndPayload(BufferedReader(StringReader(given))) shouldBe want
}
}
context("in case X") { /* previous code */ }
allows nested naming... which is another plus. And coroutines support, a bunch of plugins and extensions...Sandymcp
10/26/2021, 8:18 AMdave08
10/26/2021, 9:22 AM