-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gets the existing tests working as is. Follow-up commits will refactor the tests.
- Loading branch information
1 parent
9284325
commit 7cb0325
Showing
6 changed files
with
31 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
Allows to perform a parameterized tests, in which each test case can have different inputs and | ||
expecations but in which the test preparation & execution code are shared. | ||
*/ | ||
public struct ParameterizedTest<TestParameter> { | ||
|
||
public typealias Expectation = (TestParameter) -> Void | ||
public typealias TestCase = (TestParameter, expectation: Expectation) | ||
public typealias TestClosure = (TestParameter, Expectation) -> Void | ||
|
||
public static func test(testCases: [TestCase], testClosure: TestClosure) { | ||
testCases.forEach { testClosure($0.0, $0.expectation) } | ||
} | ||
} | ||
|
||
/// Run the same expectation code for any number of single parameter cases | ||
/// | ||
/// Note: For type inferencing to work on nil cases, you may have to do two things: | ||
/// | ||
/// (1) order the nil case first in the list of cases | ||
/// | ||
/// (2) explicitly type the nil, e.g. `Optional<String>()` | ||
public func parameterize<A>(cases: A..., expectation: ((A) -> Void)) { | ||
cases.forEach { expectation($0) } | ||
} |