Parameter

public enum Parameter<ValueType>

Parameter wraps method attribute, allowing to make a difference between explicit value, expressed by .value case and wildcard value, expressed by .any case.

Whole idea is to be able to test and specify behaviours, in both generic and explicit way (and any mix of these two). Every test method matches mock methods in signature, but changes attributes types to Parameter.

That allows pattern like matching between two Parameter values:

  • .any is equal to every other parameter. (!!! actual case name is ._, but it is advised to use .any)
  • .value(p1) is equal to .value(p2) only, when p1 == p2

Important! Comparing parameters, where ValueType is not Equatable will result in fatalError, unless you register comparator for its ValueType in Matcher instance used (typically Matcher.default)

  • any: represents and matches any parameter value
  • value: represents explicit parameter value
  • _

    Wildcard - any value

    Declaration

    Swift

    case `_`
  • Explicit value

    Declaration

    Swift

    case value(ValueType)
  • Any value matching

    Declaration

    Swift

    case matching((ValueType) -> Bool)
  • any

    Represents and matches any parameter value - syntactic sugar for ._ case.

    Declaration

    Swift

    public static var any: Parameter<ValueType> { get }
  • Represents and matches any parameter value - syntactic sugar for ._ case. Used, when needs to explicitely specify wrapped ValueType type, to resolve ambiguity between methods with same signatures, but different attribute types.

    Declaration

    Swift

    public static func any<T>(_ type: T.Type) -> Parameter<T>

    Parameters

    type

    Explicitly specify ValueType type

    Return Value

    any parameter

  • Key

    Declaration

    Swift

    public typealias Key = ValueType.Key
  • Declaration

    Swift

    public typealias Value = ValueType.Value
  • Declaration

    Swift

    public init(dictionaryLiteral elements: (Key, Value)...)
  • Used for invocations sorting purpose.

    Declaration

    Swift

    var intValue: Int { get }
  • Used for invocations sorting purpose.

    Declaration

    Swift

    var intValue: Int { get }
  • Returns whether given two parameters are matching each other, with following rules:

    1. if parameter is .any - it is equal to any other parameter
    2. if both are .value - then compare wrapped ValueType instances.
    3. if they are not Equatable (or not a Sequences of Equatable), use provided matcher instance

    Declaration

    Swift

    static func compare(lhs: Parameter<ValueType>, rhs: Parameter<ValueType>, with matcher: Matcher) -> Bool

    Parameters

    lhs

    First parameter

    rhs

    Second parameter

    matcher

    Matcher instance

    Return Value

    true, if first is matching second

  • [Internal] Wraps as generic Parameter instance. Should not be ever called directly.

    Declaration

    Swift

    func wrapAsGeneric() -> Parameter<GenericAttribute>

    Return Value

    Wrapped parameter

  • [Internal] Compare two parameters

    Declaration

    Swift

    static func compare(lhs: Parameter<ValueType>, rhs: Parameter<ValueType>, with matcher: Matcher) -> Bool

    Parameters

    lhs

    one

    rhs

    other

    matcher

    Matcher instance used for comparison

    Return Value

    true if they are matching, false otherwise

  • [Internal] Compare two parameters

    Declaration

    Swift

    static func compare(lhs: Parameter<ValueType>, rhs: Parameter<ValueType>, with matcher: Matcher) -> Bool

    Parameters

    lhs

    one

    rhs

    other

    matcher

    Matcher instance used for comparison

    Return Value

    true if they are matching, false otherwise

  • [Internal] Compare two parameters

    Declaration

    Swift

    static func compare(lhs: Parameter<ValueType>, rhs: Parameter<ValueType>, with matcher: Matcher) -> Bool

    Parameters

    lhs

    one

    rhs

    other

    matcher

    Matcher instance used for comparison

    Return Value

    true if they are matching, false otherwise

  • [Internal] Compare two parameters

    Declaration

    Swift

    static func compare(lhs: Parameter<ValueType>, rhs: Parameter<ValueType>, with matcher: Matcher) -> Bool

    Parameters

    lhs

    one

    rhs

    other

    matcher

    Matcher instance used for comparison

    Return Value

    true if they are matching, false otherwise

  • Element

    Declaration

    Swift

    typealias Element = ValueType.Element
  • [Internal] Compare two parameters

    Declaration

    Swift

    static func compare(lhs: Parameter<ValueType>, rhs: Parameter<ValueType>, with matcher: Matcher) -> Bool

    Parameters

    lhs

    one

    rhs

    other

    matcher

    Matcher instance used for comparison

    Return Value

    true if they are matching, false otherwise

  • [Internal] Wraps as generic Parameter instance. Should not be ever called directly.

    Declaration

    Swift

    func wrapAsGeneric() -> Parameter<GenericAttribute>

    Return Value

    Wrapped parameter

  • [Internal] Compare two parameters

    Declaration

    Swift

    static func compare(lhs: Parameter<ValueType>, rhs: Parameter<ValueType>, with matcher: Matcher) -> Bool

    Parameters

    lhs

    one

    rhs

    other

    matcher

    Matcher instance used for comparison

    Return Value

    true if they are matching, false otherwise