I am wondering about the best approach to deal wit...
# kotest
d
I am wondering about the best approach to deal with comparing multi-line strings to expected values. I ran into the following setup a couple of times now:
Copy code
val data = readSomeData() // reads a file from /src/test/resources
val actual = mangle(data)
actual shouldBe """
    line 1
    line 2
    """.trimIndent()
The problem is that line separators can be different between the file and Kotlin multiline strings. How to deal with that in the most convenient way possible?
k
One way I might do it is
actual.lines().shouldContainExactly("line 1", "line 2")
d
I haven't tried that yet. So far, I have only played with replacing line separators.
it looses the easily readable multi-line string, though
k
One problem you might encounter when using
trimIndent
is that it swallows the last line terminator, so if your data ends with a newline, it won't match. With
lines()
you get a blank last line.
💯 1
d
I think, I'll go with a custom matcher that ignores the line separators. I can handle all the special cases inside that code.
e
Hmm.. iirc there was a proposal to create an assertion/matcher for strings that ignore lind endings
a
note that String matching gets a lot of improvements in 6.0