-
-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #884 from Quick/9.x-tuple-equal
[9.x] Add support for tuples of up to 6 elements to `equal` matcher, as with the standard library
- Loading branch information
Showing
4 changed files
with
157 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// swiftlint:disable large_tuple vertical_whitespace | ||
|
||
// MARK: Tuple2 | ||
|
||
/// A Nimble matcher that succeeds when the actual tuple is equal to the expected tuple. | ||
/// Values can support equal by supporting the Equatable protocol. | ||
public func equal<T1: Equatable, T2: Equatable>( | ||
_ expectedValue: (T1, T2)? | ||
) -> Predicate<(T1, T2)> { | ||
equal(expectedValue, by: ==) | ||
} | ||
|
||
public func ==<T1: Equatable, T2: Equatable>( | ||
lhs: Expectation<(T1, T2)>, | ||
rhs: (T1, T2)? | ||
) { | ||
lhs.to(equal(rhs)) | ||
} | ||
|
||
public func !=<T1: Equatable, T2: Equatable>( | ||
lhs: Expectation<(T1, T2)>, | ||
rhs: (T1, T2)? | ||
) { | ||
lhs.toNot(equal(rhs)) | ||
} | ||
|
||
|
||
// MARK: Tuple3 | ||
|
||
/// A Nimble matcher that succeeds when the actual tuple is equal to the expected tuple. | ||
/// Values can support equal by supporting the Equatable protocol. | ||
public func equal<T1: Equatable, T2: Equatable, T3: Equatable>( | ||
_ expectedValue: (T1, T2, T3)? | ||
) -> Predicate<(T1, T2, T3)> { | ||
equal(expectedValue, by: ==) | ||
} | ||
|
||
public func ==<T1: Equatable, T2: Equatable, T3: Equatable>( | ||
lhs: Expectation<(T1, T2, T3)>, | ||
rhs: (T1, T2, T3)? | ||
) { | ||
lhs.to(equal(rhs)) | ||
} | ||
|
||
public func !=<T1: Equatable, T2: Equatable, T3: Equatable>( | ||
lhs: Expectation<(T1, T2, T3)>, | ||
rhs: (T1, T2, T3)? | ||
) { | ||
lhs.toNot(equal(rhs)) | ||
} | ||
|
||
|
||
// MARK: Tuple4 | ||
|
||
/// A Nimble matcher that succeeds when the actual tuple is equal to the expected tuple. | ||
/// Values can support equal by supporting the Equatable protocol. | ||
public func equal<T1: Equatable, T2: Equatable, T3: Equatable, T4: Equatable>( | ||
_ expectedValue: (T1, T2, T3, T4)? | ||
) -> Predicate<(T1, T2, T3, T4)> { | ||
equal(expectedValue, by: ==) | ||
} | ||
|
||
public func ==<T1: Equatable, T2: Equatable, T3: Equatable, T4: Equatable>( | ||
lhs: Expectation<(T1, T2, T3, T4)>, | ||
rhs: (T1, T2, T3, T4)? | ||
) { | ||
lhs.to(equal(rhs)) | ||
} | ||
|
||
public func !=<T1: Equatable, T2: Equatable, T3: Equatable, T4: Equatable>( | ||
lhs: Expectation<(T1, T2, T3, T4)>, | ||
rhs: (T1, T2, T3, T4)? | ||
) { | ||
lhs.toNot(equal(rhs)) | ||
} | ||
|
||
|
||
// MARK: Tuple5 | ||
|
||
/// A Nimble matcher that succeeds when the actual tuple is equal to the expected tuple. | ||
/// Values can support equal by supporting the Equatable protocol. | ||
public func equal<T1: Equatable, T2: Equatable, T3: Equatable, T4: Equatable, T5: Equatable>( | ||
_ expectedValue: (T1, T2, T3, T4, T5)? | ||
) -> Predicate<(T1, T2, T3, T4, T5)> { | ||
equal(expectedValue, by: ==) | ||
} | ||
|
||
public func ==<T1: Equatable, T2: Equatable, T3: Equatable, T4: Equatable, T5: Equatable>( | ||
lhs: Expectation<(T1, T2, T3, T4, T5)>, | ||
rhs: (T1, T2, T3, T4, T5)? | ||
) { | ||
lhs.to(equal(rhs)) | ||
} | ||
|
||
public func !=<T1: Equatable, T2: Equatable, T3: Equatable, T4: Equatable, T5: Equatable>( | ||
lhs: Expectation<(T1, T2, T3, T4, T5)>, | ||
rhs: (T1, T2, T3, T4, T5)? | ||
) { | ||
lhs.toNot(equal(rhs)) | ||
} | ||
|
||
|
||
// MARK: Tuple6 | ||
|
||
/// A Nimble matcher that succeeds when the actual tuple is equal to the expected tuple. | ||
/// Values can support equal by supporting the Equatable protocol. | ||
public func equal<T1: Equatable, T2: Equatable, T3: Equatable, T4: Equatable, T5: Equatable, T6: Equatable>( | ||
_ expectedValue: (T1, T2, T3, T4, T5, T6)? | ||
) -> Predicate<(T1, T2, T3, T4, T5, T6)> { | ||
equal(expectedValue, by: ==) | ||
} | ||
|
||
public func ==<T1: Equatable, T2: Equatable, T3: Equatable, T4: Equatable, T5: Equatable, T6: Equatable>( | ||
lhs: Expectation<(T1, T2, T3, T4, T5, T6)>, | ||
rhs: (T1, T2, T3, T4, T5, T6)? | ||
) { | ||
lhs.to(equal(rhs)) | ||
} | ||
|
||
public func !=<T1: Equatable, T2: Equatable, T3: Equatable, T4: Equatable, T5: Equatable, T6: Equatable>( | ||
lhs: Expectation<(T1, T2, T3, T4, T5, T6)>, | ||
rhs: (T1, T2, T3, T4, T5, T6)? | ||
) { | ||
lhs.toNot(equal(rhs)) | ||
} | ||
|
||
// swiftlint:enable large_tuple vertical_whitespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters