Skip to content

Instantly share code, notes, and snippets.

@oguzhanaslann
Created July 30, 2023 10:56
Show Gist options
  • Select an option

  • Save oguzhanaslann/ce9d1271942f0255687856bd064fd84c to your computer and use it in GitHub Desktop.

Select an option

Save oguzhanaslann/ce9d1271942f0255687856bd064fd84c to your computer and use it in GitHub Desktop.
test helper functions in "given-when-then" for better readability
data class Given<T>(val state: T)
data class When<T>(val scenario: T)
data class Then<T>(val result: T)
fun <T> given(block: () -> T) = Given<T>(block())
infix fun <T, R> Given<T>.check(block: (T) -> R): When<R> {
val state = this.state
return When(block(state))
}
infix fun <T, R> When<T>.then(block: (T) -> R): Then<R> {
val happened = this.scenario
return Then(block(happened))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment