Created
January 19, 2023 00:42
-
-
Save klein-artur/18792d4779ec9ae3089773ea88edd9ed to your computer and use it in GitHub Desktop.
Checking Result for success or error in Tests
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
extension Result where Failure == ParseError { | |
func checkError(messageIfNotError: String, type: ParseErrorType) { | |
switch self { | |
case .success(_): | |
XCTFail(messageIfNotError) | |
case let .failure(error): | |
if error.type != type { | |
XCTFail("Should have thrown \(type.rawValue) but did \(error.type)") | |
} | |
} | |
} | |
func checkSuccess(checker: ((Success) -> Void)) { | |
switch self { | |
case let .success(value): | |
checker(value) | |
case let .failure(error): | |
XCTFail("Should have succeeded, but failed with \(error).") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment