AsyncMatcher

public struct AsyncMatcher<T> : AsyncableMatcher

An AsyncMatcher is part of the new matcher API that provides assertions to expectations.

Given a code snippet:

expect(1).to(equal(2)) ^^^^^^^^ Called a “matcher”

A matcher consists of two parts a constructor function and the Matcher.

The Matcher provide the heavy lifting on how to assert against a given value. Internally, matchers are simple wrappers around closures to provide static type information and allow composition and wrapping of existing behaviors.

AsyncMatchers serve to allow writing matchers that must be run in async contexts. These can also be used with either Expectations or AsyncExpectations. But these can only be used from async contexts, and are unavailable in Objective-C. You can, however, call regular Matchers from an AsyncMatcher, if you wish to compose one like that.

  • Undocumented

    Declaration

    Swift

    public init(_ matcher: @escaping (AsyncExpression<T>) async throws -> MatcherResult)
  • satisfies(_:) Asynchronous

    Uses a matcher on a given value to see if it passes the matcher.

    @param expression The value to run the matcher’s logic against @returns A matcher result indicate passing or failing and an associated error message.

    Declaration

    Swift

    public func satisfies(_ expression: AsyncExpression<T>) async throws -> MatcherResult
  • Like Matcher() constructor, but automatically guard against nil (actual) values

    Declaration

    Swift

    public static func define(matcher: @escaping (AsyncExpression<T>) async throws -> MatcherResult) -> AsyncMatcher<T>
  • Defines a matcher with a default message that can be returned in the closure Also ensures the matcher’s actual value cannot pass with nil given.

    Declaration

    Swift

    public static func define(_ message: String = "match", matcher: @escaping (AsyncExpression<T>, ExpectationMessage) async throws -> MatcherResult) -> AsyncMatcher<T>
  • Defines a matcher with a default message that can be returned in the closure Unlike define, this allows nil values to succeed if the given closure chooses to.

    Declaration

    Swift

    public static func defineNilable(_ message: String = "match", matcher: @escaping (AsyncExpression<T>, ExpectationMessage) async throws -> MatcherResult) -> AsyncMatcher<T>
  • Provides a simple matcher definition that provides no control over the predefined error message.

    Also ensures the matcher’s actual value cannot pass with nil given.

    Declaration

    Swift

    public static func simple(_ message: String = "match", matcher: @escaping (AsyncExpression<T>) async throws -> MatcherStatus) -> AsyncMatcher<T>
  • Provides a simple matcher definition that provides no control over the predefined error message.

    Unlike simple, this allows nil values to succeed if the given closure chooses to.

    Declaration

    Swift

    public static func simpleNilable(_ message: String = "match", matcher: @escaping (AsyncExpression<T>) async throws -> MatcherStatus) -> AsyncMatcher<T>
  • Returns a new Matcher based on the current one that always fails if nil is given as the actual value.

    Declaration

    Swift

    public var requireNonNil: AsyncMatcher<T> { get }