2 ms·
Funny seeing that relatively old article, when you consider that JetBrains made good on that promise: Kotlin made writing DSLs actually pleasant. class Mod
by ohgodplsno 4y ago
Funny seeing that relatively old article, when you consider that JetBrains made good on that promise: Kotlin made writing DSLs actually pleasant.
class ModuleTest: StringSpec({
"it should behave well" {
2 + 4 shouldBe 6
"test" shouldBeInstanceOf<String>()
}
})
This includes many things that Kotlin makes use of, like String.invoke(block: () -> Unit) which is both an extension on String instances and makes uses of Kotlin's "ability" to move lambdas out of parentheses if they are the last argument (so something like log(lazyString: () -> String), can be used as log({ "message" }), or log { "message" }, @DslMarker (to allow a String.invoke(() -> Unit) block in the form of "it should behave well", only inside the context of a StringSpec.), infix funs (+ is infix operator fun plus(), with some slightly specific language handling because it's extremely common, infix fun shouldBe). This is using Kotest (https://kotest.io/docs/framework/writing-tests.html https://kotest.io/docs/framework/writing-tests.html), but other tools like Ktor, Skrape.it (https://github.com/skrapeit/skrape.it https://github.com/skrapeit/skrape.it), and more: https://kotlinlang.org/docs/type-safe-builders.html https://kotlinlang.org/docs/type-safe-builders.html