Created
July 30, 2023 10:56
-
-
Save oguzhanaslann/ce9d1271942f0255687856bd064fd84c to your computer and use it in GitHub Desktop.
test helper functions in "given-when-then" for better readability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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