AsyncExpression

public struct AsyncExpression<Value>

Expression represents the closure of the value inside expect(…). Expressions are memoized by default. This makes them safe to call evaluate() multiple times without causing a re-evaluation of the underlying closure.

Warning

Since the closure can be any code, Objective-C code may choose to raise an exception. Currently, SyncExpression does not memoize exception raising.

This provides a common consumable API for matchers to utilize to allow Nimble to change internals to how the captured closure is managed.

  • Undocumented

    Declaration

    Swift

    public let location: SourceLocation
  • Undocumented

    Declaration

    Swift

    public let isClosure: Bool
  • Creates a new expression struct. Normally, expect(…) will manage this creation process. The expression is memoized.

    Declaration

    Swift

    public init(expression: @escaping () async throws -> Value?, location: SourceLocation, isClosure: Bool = true)

    Parameters

    expression

    The closure that produces a given value.

    location

    The source location that this closure originates from.

    isClosure

    A bool indicating if the captured expression is a closure or internally produced closure. Some matchers may require closures. For example, toEventually() requires an explicit closure. This gives Nimble flexibility if @autoclosure behavior changes between Swift versions. Nimble internals always sets this true.

  • Creates a new expression struct. Normally, expect(…) will manage this creation process.

    Declaration

    Swift

    public init(memoizedExpression: @escaping (Bool) async throws -> Value?, location: SourceLocation, withoutCaching: Bool, isClosure: Bool = true)

    Parameters

    expression

    The closure that produces a given value.

    location

    The source location that this closure originates from.

    withoutCaching

    Indicates if the struct should memoize the given closure’s result. Subsequent evaluate() calls will not call the given closure if this is true.

    isClosure

    A bool indicating if the captured expression is a closure or internally produced closure. Some matchers may require closures. For example, toEventually() requires an explicit closure. This gives Nimble flexibility if @autoclosure behavior changes between Swift versions. Nimble internals always sets this true.

  • Creates a new synchronous expression, for use in Predicates.

    Declaration

    Swift

    public func toSynchronousExpression() async -> Expression<Value>
  • Returns a new Expression from the given expression. Identical to a map() on this type. This should be used only to typecast the Expression’s closure value.

    The returned expression will preserve location and isClosure.

    Declaration

    Swift

    public func cast<U>(_ block: @escaping (Value?) throws -> U?) -> AsyncExpression<U>

    Parameters

    block

    The block that can cast the current Expression value to a new type.

  • evaluate() Asynchronous

    Undocumented

    Declaration

    Swift

    public func evaluate() async throws -> Value?
  • Undocumented

    Declaration

    Swift

    public func withoutCaching() -> AsyncExpression<Value>
  • Undocumented

    Declaration

    Swift

    public func withCaching() -> AsyncExpression<Value>