mirror of
https://github.com/irmen/prog8.git
synced 2026-10-22 05:02:58 +00:00
19 lines
602 B
Kotlin
19 lines
602 B
Kotlin
package prog8tests.helpers
|
|
|
|
import io.kotest.assertions.fail
|
|
|
|
/**
|
|
* Asserts that the string contains the given [substrings] in the specified order.
|
|
* This is much faster than using a large multi-line Regex.
|
|
*/
|
|
fun String.shouldContainInOrder(vararg substrings: String) {
|
|
var currentSearchIndex = 0
|
|
for (substring in substrings) {
|
|
val index = this.indexOf(substring, currentSearchIndex)
|
|
if (index == -1) {
|
|
fail("Could not find '$substring' after index $currentSearchIndex in string:\n$this")
|
|
}
|
|
currentSearchIndex = index + substring.length
|
|
}
|
|
}
|