Skip to content

Expression

Oleksandr Bretsko edited this page Dec 27, 2020 · 1 revision

Expression

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.

public struct Expression<T>

@warning Since the closure can be any code, Objective-C code may choose to raise an exception. Currently, Expression 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.

Initializers

init(expression:location:isClosure:)

Creates a new expression struct. Normally, expect(...) will manage this creation process. The expression is memoized.

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

@param expression The closure that produces a given value. @param location The source location that this closure originates from. @param 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.

init(memoizedExpression:location:withoutCaching:isClosure:)

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

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

@param expression The closure that produces a given value. @param location The source location that this closure originates from. @param 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. @param 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.

init(expression:location:isClosure:)

Creates a new expression struct. Normally, expect(...) will manage this creation process. The expression is memoized.

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

@param expression The closure that produces a given value. @param location The source location that this closure originates from. @param 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.

init(memoizedExpression:location:withoutCaching:isClosure:)

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

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

@param expression The closure that produces a given value. @param location The source location that this closure originates from. @param 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. @param 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.

Properties

location

let location: SourceLocation

isClosure

let isClosure: Bool

location

let location: SourceLocation

isClosure

let isClosure: Bool

Methods

cast(_:)

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.

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

The returned expression will preserve location and isClosure.

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

evaluate()

public func evaluate() throws -> T?

withoutCaching()

public func withoutCaching() -> Expression<T>

cast(_:)

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.

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

The returned expression will preserve location and isClosure.

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

evaluate()

public func evaluate() throws -> T?

withoutCaching()

public func withoutCaching() -> Expression<T>
Types
Protocols
Global Typealiases
Global Variables
Global Functions
  • MACH_MSGH_BITS(_:_:)
  • MACH_MSGH_BITS_REMOTE(_:)
  • QCKMain(_:configurations:testCases:)
  • __allTests()
  • afterEach(_:)
  • afterSuite(_:)
  • allPass(_:)
  • allPass(_:_:)
  • assertClose(_:_:allowedError:file:line:)
  • assertClose(_:_:allowedError:worstError:file:line:)
  • be(_:)
  • beAKindOf(_:)
  • beAnInstanceOf(_:)
  • beCloseTo(_:within:)
  • beEmpty()
  • beFalse()
  • beFalsy()
  • beGreaterThan(_:)
  • beGreaterThanOrEqualTo(_:)
  • beIdenticalTo(_:)
  • beLessThan(_:)
  • beLessThanOrEqualTo(_:)
  • beNil()
  • beTrue()
  • beTruthy()
  • beVoid()
  • beforeEach(_:)
  • beforeSuite(_:)
  • beginWith(_:)
  • catchBadInstruction(block:)
  • catchBadInstruction(in:)
  • chain(_:_:)
  • contain(_:)
  • containElementSatisfying(_:_:)
  • context(_:flags:closure:)
  • crashIf(_:_:)
  • crashIfAnyFalse(_:_:)
  • crashIfAnyFalse(_:crashMessage:)
  • crashIfAnyFalse(_:message:)
  • crashIfAnyNotExpected(_:expected:_:)
  • crashIfAnyNotExpected(_:expected:crashMessage:)
  • crashIfAnyTrue(_:_:)
  • crashIfFalse(_:_:)
  • crashIfNegative(_:)
  • crashIfNil(_:)
  • crashIfNotEqual(_:)
  • crashIfNotEqual(_:_:)
  • crashIfNotExpected(_:expected:_:)
  • crashIfNotNil(_:)
  • describe(_:flags:closure:)
  • doubleForLoop(_:_:)
  • elementsEqual(_:)
  • elementsEqual(_:by:)
  • encode(encodable:)
  • endWith(_:)
  • equal(_:)
  • expect(_:file:line:)
  • expect(_:line:expression:)
  • fail(_:file:line:)
  • fail(_:line:)
  • fail(_:location:)
  • fcontext(_:flags:closure:)
  • fdescribe(_:flags:closure:)
  • fit(_:flags:file:line:closure:)
  • fitBehavesLike(_:flags:file:line:)
  • fitBehavesLike(_:flags:file:line:context:)
  • fitBehavesLike(_:flags:file:line:sharedExampleContext:)
  • gatherExpectations(silently:closure:)
  • gatherFailingExpectations(silently:closure:)
  • haveCount(_:)
  • isValidLength(_:)
  • it(_:flags:file:line:closure:)
  • itBehavesLike(_:flags:file:line:)
  • itBehavesLike(_:flags:file:line:context:)
  • itBehavesLike(_:flags:file:line:sharedExampleContext:)
  • match(_:)
  • matchError(_:)
  • pending(_:closure:)
  • postNotifications(_:fromNotificationCenter:)
  • prettyCollectionType(_:)
  • product(_:_:)
  • raiseException(named:reason:userInfo:closure:)
  • recordFailure(_:location:)
  • satisfyAllOf(_:)
  • satisfyAnyOf(_:)
  • sharedExamples(_:closure:)
  • stringify(_:)
  • succeed()
  • threadSingleton(_:)
  • throwAssertion()
  • throwError()
  • throwError(_:closure:)
  • throwError(closure:)
  • throwError(errorType:closure:)
  • uuid()
  • waitUntil(timeout:file:line:action:)
  • withAssertionHandler(_:file:line:closure:)
  • xcontext(_:flags:closure:)
  • xdescribe(_:flags:closure:)
  • xit(_:flags:file:line:closure:)
  • xitBehavesLike(_:flags:file:line:context:)
Operators
  • !=(lhs:rhs:)
  • !==(lhs:rhs:)
  • &&(left:right:)
  • **(lhs:rhs:)
  • <(lhs:rhs:)
  • <=(lhs:rhs:)
  • ==(lhs:rhs:)
  • ===(lhs:rhs:)
  • >(lhs:rhs:)
  • >=(lhs:rhs:)
  • ||(left:right:)
  • ~=(regex:input:)
  • ±(Float:)
  • ±(double:)
  • ±(lhs:rhs:)
  • √(double:)
  • ≈(lhs:rhs:)

Clone this wiki locally