// build.gradle.kts:
// testImplementation("org.junit.jupiter:junit-jupiter:5.10.+")
// testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.+")
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.*
import kotlin.test.Test
fun slugify(s: String): String =
s.lowercase().replace(Regex("[^a-z0-9]+"), "-").trim('-')
class SlugifyTest {
@ParameterizedTest(name = "[{index}] slugify({0}) → {1}")
@CsvSource(
"Hello World, hello-world",
" Trim Me , trim-me",
"PHP 8.3, php-8-3",
"double--dashes, double-dashes",
)
fun slugify_examples(input: String, expected: String) {
assertEquals(expected, slugify(input))
}
@ParameterizedTest
@ValueSource(strings = ["a", "b", "c"])
fun every_value_is_uppercased(s: String) {
assertEquals(s.uppercase(), s.uppercase())
}
}
Create a free account and build your private vault. Share publicly whenever you want.