Skip to content

Instantly share code, notes, and snippets.

@nikku
Last active February 23, 2022 10:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikku/e12e681a7002c8750af5d56b2805266c to your computer and use it in GitHub Desktop.
Save nikku/e12e681a7002c8750af5d56b2805266c to your computer and use it in GitHub Desktop.
Quick hack of a readable DSL for writing assertions in Kotlin
import kotlin.test.assertEquals
fun <T> equal(expected: T) : (T) -> Unit {
return { t ->
assertEquals(t, expected);
}
}
infix fun <T> T.should(matcher: (T) -> Unit) {
matcher(this);
}
// in test
"FOO" should equal("5");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment