Skip to content

Instantly share code, notes, and snippets.

@klein-artur
Created January 19, 2023 00:42
Show Gist options
  • Save klein-artur/18792d4779ec9ae3089773ea88edd9ed to your computer and use it in GitHub Desktop.
Save klein-artur/18792d4779ec9ae3089773ea88edd9ed to your computer and use it in GitHub Desktop.
Checking Result for success or error in Tests
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