Skip to content

Predicate

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

Predicate

A Predicate is part of the new matcher API that provides assertions to expectations.

public struct Predicate<T>

Given a code snippet:

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

A matcher consists of two parts a constructor function and the Predicate. The term Predicate is used as a separate name from Matcher to help transition custom matchers to the new Nimble matcher API.

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

Inheritance

Matcher, Matcher, Matcher, Matcher

Initializers

init(_:)

Constructs a predicate that knows how take a given value

public init(_ matcher: @escaping (Expression<T>) throws -> PredicateResult)

init(_:)

Constructs a predicate that knows how take a given value

public init(_ matcher: @escaping (Expression<T>) throws -> PredicateResult)

Properties

requireNonNil

Returns a new Predicate based on the current one that always fails if nil is given as the actual value.

var requireNonNil: Predicate<T>

This replaces NonNilMatcherFunc.

requireNonNil

Returns a new Predicate based on the current one that always fails if nil is given as the actual value.

var requireNonNil: Predicate<T>

This replaces NonNilMatcherFunc.

Methods

satisfies(_:)

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

public func satisfies(_ expression: Expression<T>) throws -> PredicateResult

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

define(matcher:)

Like Predicate() constructor, but automatically guard against nil (actual) values

public static func define(matcher: @escaping (Expression<T>) throws -> PredicateResult) -> Predicate<T>

define(_:matcher:)

Defines a predicate with a default message that can be returned in the closure Also ensures the predicate's actual value cannot pass with nil given.

public static func define(_ msg: String, matcher: @escaping (Expression<T>, ExpectationMessage) throws -> PredicateResult) -> Predicate<T>

defineNilable(_:matcher:)

Defines a predicate 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.

public static func defineNilable(_ msg: String, matcher: @escaping (Expression<T>, ExpectationMessage) throws -> PredicateResult) -> Predicate<T>

simple(_:matcher:)

Provides a simple predicate definition that provides no control over the predefined error message.

public static func simple(_ msg: String, matcher: @escaping (Expression<T>) throws -> PredicateStatus) -> Predicate<T>

Also ensures the predicate's actual value cannot pass with nil given.

simpleNilable(_:matcher:)

Provides a simple predicate definition that provides no control over the predefined error message.

public static func simpleNilable(_ msg: String, matcher: @escaping (Expression<T>) throws -> PredicateStatus) -> Predicate<T>

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

fromDeprecatedFullClosure(_:)

Compatibility layer for old Matcher API, deprecated

public static func fromDeprecatedFullClosure(_ matcher: @escaping (Expression<T>, FailureMessage, Bool) throws -> Bool) -> Predicate

fromDeprecatedClosure(_:)

Compatibility layer for old Matcher API, deprecated. Emulates the MatcherFunc API

public static func fromDeprecatedClosure(_ matcher: @escaping (Expression<T>, FailureMessage) throws -> Bool) -> Predicate

fromDeprecatedMatcher(_:)

Compatibility layer for old Matcher API, deprecated. Same as calling .predicate on a MatcherFunc or NonNilMatcherFunc type.

public static func fromDeprecatedMatcher<M>(_ matcher: M) -> Predicate where M: Matcher, M.ValueType == T

matches(_:failureMessage:)

Deprecated Matcher API, use satisfies(:​) instead

public func matches(_ actualExpression: Expression<T>, failureMessage: FailureMessage) throws -> Bool

doesNotMatch(_:failureMessage:)

Deprecated Matcher API, use satisfies(:​) instead

public func doesNotMatch(_ actualExpression: Expression<T>, failureMessage: FailureMessage) throws -> Bool

satisfies(_:)

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

public func satisfies(_ expression: Expression<T>) throws -> PredicateResult

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

define(matcher:)

Like Predicate() constructor, but automatically guard against nil (actual) values

public static func define(matcher: @escaping (Expression<T>) throws -> PredicateResult) -> Predicate<T>

define(_:matcher:)

Defines a predicate with a default message that can be returned in the closure Also ensures the predicate's actual value cannot pass with nil given.

public static func define(_ msg: String, matcher: @escaping (Expression<T>, ExpectationMessage) throws -> PredicateResult) -> Predicate<T>

defineNilable(_:matcher:)

Defines a predicate 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.

public static func defineNilable(_ msg: String, matcher: @escaping (Expression<T>, ExpectationMessage) throws -> PredicateResult) -> Predicate<T>

simple(_:matcher:)

Provides a simple predicate definition that provides no control over the predefined error message.

public static func simple(_ msg: String, matcher: @escaping (Expression<T>) throws -> PredicateStatus) -> Predicate<T>

Also ensures the predicate's actual value cannot pass with nil given.

simpleNilable(_:matcher:)

Provides a simple predicate definition that provides no control over the predefined error message.

public static func simpleNilable(_ msg: String, matcher: @escaping (Expression<T>) throws -> PredicateStatus) -> Predicate<T>

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

fromDeprecatedFullClosure(_:)

Compatibility layer for old Matcher API, deprecated

public static func fromDeprecatedFullClosure(_ matcher: @escaping (Expression<T>, FailureMessage, Bool) throws -> Bool) -> Predicate

fromDeprecatedClosure(_:)

Compatibility layer for old Matcher API, deprecated. Emulates the MatcherFunc API

public static func fromDeprecatedClosure(_ matcher: @escaping (Expression<T>, FailureMessage) throws -> Bool) -> Predicate

fromDeprecatedMatcher(_:)

Compatibility layer for old Matcher API, deprecated. Same as calling .predicate on a MatcherFunc or NonNilMatcherFunc type.

public static func fromDeprecatedMatcher<M>(_ matcher: M) -> Predicate where M: Matcher, M.ValueType == T

matches(_:failureMessage:)

Deprecated Matcher API, use satisfies(:​) instead

public func matches(_ actualExpression: Expression<T>, failureMessage: FailureMessage) throws -> Bool

doesNotMatch(_:failureMessage:)

Deprecated Matcher API, use satisfies(:​) instead

public func doesNotMatch(_ actualExpression: Expression<T>, failureMessage: FailureMessage) throws -> Bool
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