-
-
Save chosa91/77d130443e55bebda3812b21ddee74dc to your computer and use it in GitHub Desktop.
FunctionBuilder mvp for a given/when/then test setup
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
| test { | |
| "Hello world" | |
| given { print("GIVEN:", $0) } | |
| when { print("WHEN:", $0) } | |
| then { print("Then:", $0) } | |
| } |
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
| import XCTest | |
| @_functionBuilder | |
| struct Test<T> { | |
| var data: T | |
| var given: given<T> | |
| var when: when<T> | |
| var then: then<T> | |
| func execute() { | |
| given.execute(data) | |
| when.execute(data) | |
| then.execute(data) | |
| } | |
| static func buildBlock(_ data: T, _ given: given<T>, _ when: when<T>, _ then: then<T>) -> Test { | |
| return Test(data: data, given: given, when: when, then: then) | |
| } | |
| } | |
| struct given<T> { | |
| let execute: (T) -> Void | |
| } | |
| struct when<T> { | |
| let execute: (T) -> Void | |
| } | |
| struct then<T> { | |
| let execute: (T) -> Void | |
| } | |
| func test<T>(@Test<T> test: () -> Test<T>) { | |
| test().execute() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment