Using extensions with lambdas
suggest changeIf you have:
operator fun String.invoke(block: () -> Unit) {
try {
block()
} catch (e: AssertException) {
System.err.println("$this\n${e.message}")
}
}
You can write the following DSL-like code:
"it should return 2" {
parse("1 + 1").buildAST().evaluate() shouldBe 2
}
If you feel confused with shouldBe above, see the example Infix approach to build DSL.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents