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
-
Represents and matches any parameter value - syntactic sugar for
._
case.Declaration
Swift
public static var any: Parameter<ValueType>
-
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
-
Used for invocations sorting purpose.
Declaration
Swift
public var intValue: Int
-
Returns whether given two parameters are matching each other, with following rules:
- if parameter is .any - it is equal to any other parameter
- if both are .value - then compare wrapped ValueType instances.
- if they are not Equatable (or not a Sequences of Equatable), use provided matcher instance
Declaration
Swift
public 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
public func wrapAsGeneric() -> Parameter<GenericAttribute>
Return Value
Wrapped parameter