mirror of
https://github.com/mas-cli/mas
synced 2024-11-22 19:43:09 +00:00
e6e2ccab0d
swiftformat Sources Tests
32 lines
1 KiB
Swift
32 lines
1 KiB
Swift
//
|
|
// ResultPredicates.swift
|
|
// MasKitTests
|
|
//
|
|
// Created by Ben Chatelain on 12/27/18.
|
|
// Copyright © 2018 mas-cli. All rights reserved.
|
|
//
|
|
|
|
import Nimble
|
|
|
|
@testable import MasKit
|
|
|
|
/// Nimble predicate for result enum success case, no associated value
|
|
func beSuccess() -> Predicate<Result<Void, MASError>> {
|
|
Predicate.define("be <success>") { expression, message in
|
|
if case .success = try expression.evaluate() {
|
|
return PredicateResult(status: .matches, message: message)
|
|
}
|
|
return PredicateResult(status: .fail, message: message)
|
|
}
|
|
}
|
|
|
|
/// Nimble predicate for result enum failure with associated error
|
|
func beFailure(test: @escaping (MASError) -> Void = { _ in }) -> Predicate<Result<Void, MASError>> {
|
|
Predicate.define("be <failure>") { expression, message in
|
|
if case .failure(let error) = try expression.evaluate() {
|
|
test(error)
|
|
return PredicateResult(status: .matches, message: message)
|
|
}
|
|
return PredicateResult(status: .fail, message: message)
|
|
}
|
|
}
|