Skip to content

Commit 281a11b

Browse files
committed
Simplify equal matcher implementation
1 parent d2c1301 commit 281a11b

File tree

2 files changed

+2
-40
lines changed

2 files changed

+2
-40
lines changed

Sources/Nimble/Matchers/Equal.swift

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,15 @@ public func equal<T: Equatable>(_ expectedValue: T?) -> Predicate<T> {
2424
equal(expectedValue, by: ==)
2525
}
2626

27-
/// A Nimble matcher allowing comparison of collection with optional type
28-
public func equal<T: Equatable>(_ expectedValue: [T?]) -> Predicate<[T?]> {
29-
return Predicate.define("equal <\(stringify(expectedValue))>") { actualExpression, msg in
30-
guard let actualValue = try actualExpression.evaluate() else {
31-
return PredicateResult(
32-
status: .fail,
33-
message: msg.appendedBeNilHint()
34-
)
35-
}
36-
37-
let matches = expectedValue == actualValue
38-
return PredicateResult(bool: matches, message: msg)
39-
}
40-
}
41-
4227
/// A Nimble matcher that succeeds when the actual set is equal to the expected set.
4328
public func equal<T>(_ expectedValue: Set<T>?) -> Predicate<Set<T>> {
4429
return equal(expectedValue, stringify: { stringify($0) })
4530
}
4631

4732
/// A Nimble matcher that succeeds when the actual set is equal to the expected set.
4833
public func equal<T: Comparable>(_ expectedValue: Set<T>?) -> Predicate<Set<T>> {
49-
return equal(expectedValue, stringify: {
50-
if let set = $0 {
51-
return stringify(Array(set).sorted { $0 < $1 })
52-
} else {
53-
return "nil"
54-
}
34+
return equal(expectedValue, stringify: { set in
35+
stringify(set.map { Array($0).sorted(by: <) })
5536
})
5637
}
5738

@@ -118,14 +99,6 @@ public func !=<T: Equatable>(lhs: Expectation<T>, rhs: T?) {
11899
lhs.toNot(equal(rhs))
119100
}
120101

121-
public func ==<T: Equatable>(lhs: Expectation<[T]>, rhs: [T]?) {
122-
lhs.to(equal(rhs))
123-
}
124-
125-
public func !=<T: Equatable>(lhs: Expectation<[T]>, rhs: [T]?) {
126-
lhs.toNot(equal(rhs))
127-
}
128-
129102
public func == <T>(lhs: Expectation<Set<T>>, rhs: Set<T>) {
130103
lhs.to(equal(rhs))
131104
}
@@ -158,14 +131,6 @@ public func !=<T: Comparable>(lhs: Expectation<Set<T>>, rhs: Set<T>?) {
158131
lhs.toNot(equal(rhs))
159132
}
160133

161-
public func ==<T, C: Equatable>(lhs: Expectation<[T: C]>, rhs: [T: C]?) {
162-
lhs.to(equal(rhs))
163-
}
164-
165-
public func !=<T, C: Equatable>(lhs: Expectation<[T: C]>, rhs: [T: C]?) {
166-
lhs.toNot(equal(rhs))
167-
}
168-
169134
#if canImport(Darwin)
170135
import class Foundation.NSObject
171136

Tests/NimbleTests/Matchers/EqualTest.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,9 @@ final class EqualTest: XCTestCase {
150150

151151
failsWithErrorMessage("expected to equal <world>, got <hello>") {
152152
expect("hello") == "world"
153-
return
154153
}
155154
failsWithErrorMessage("expected to not equal <hello>, got <hello>") {
156155
expect("hello") != "hello"
157-
return
158156
}
159157
}
160158

@@ -215,7 +213,6 @@ final class EqualTest: XCTestCase {
215213
let arrayOfOptionalInts: [Int?] = [nil, 2]
216214
let anotherArrayOfOptionalInts: [Int?] = [1, nil]
217215
expect(arrayOfOptionalInts).to(equal(anotherArrayOfOptionalInts))
218-
return
219216
}
220217
}
221218

0 commit comments

Comments
 (0)