Skip to content

Commit d2c1301

Browse files
authored
Merge pull request #897 from Quick/equal-operators-with-implicit-member-syntax
Add more specific operator overloads for `equal` matcher
2 parents a042c86 + 1ebf31c commit d2c1301

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Sources/Nimble/Matchers/Equal.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,18 @@ private func equal<T>(_ expectedValue: Set<T>?, stringify: @escaping (Set<T>?) -
102102
}
103103
}
104104

105+
public func ==<T: Equatable>(lhs: Expectation<T>, rhs: T) {
106+
lhs.to(equal(rhs))
107+
}
108+
105109
public func ==<T: Equatable>(lhs: Expectation<T>, rhs: T?) {
106110
lhs.to(equal(rhs))
107111
}
108112

113+
public func !=<T: Equatable>(lhs: Expectation<T>, rhs: T) {
114+
lhs.toNot(equal(rhs))
115+
}
116+
109117
public func !=<T: Equatable>(lhs: Expectation<T>, rhs: T?) {
110118
lhs.toNot(equal(rhs))
111119
}
@@ -118,18 +126,34 @@ public func !=<T: Equatable>(lhs: Expectation<[T]>, rhs: [T]?) {
118126
lhs.toNot(equal(rhs))
119127
}
120128

129+
public func == <T>(lhs: Expectation<Set<T>>, rhs: Set<T>) {
130+
lhs.to(equal(rhs))
131+
}
132+
121133
public func == <T>(lhs: Expectation<Set<T>>, rhs: Set<T>?) {
122134
lhs.to(equal(rhs))
123135
}
124136

137+
public func != <T>(lhs: Expectation<Set<T>>, rhs: Set<T>) {
138+
lhs.toNot(equal(rhs))
139+
}
140+
125141
public func != <T>(lhs: Expectation<Set<T>>, rhs: Set<T>?) {
126142
lhs.toNot(equal(rhs))
127143
}
128144

145+
public func ==<T: Comparable>(lhs: Expectation<Set<T>>, rhs: Set<T>) {
146+
lhs.to(equal(rhs))
147+
}
148+
129149
public func ==<T: Comparable>(lhs: Expectation<Set<T>>, rhs: Set<T>?) {
130150
lhs.to(equal(rhs))
131151
}
132152

153+
public func !=<T: Comparable>(lhs: Expectation<Set<T>>, rhs: Set<T>) {
154+
lhs.toNot(equal(rhs))
155+
}
156+
133157
public func !=<T: Comparable>(lhs: Expectation<Set<T>>, rhs: Set<T>?) {
134158
lhs.toNot(equal(rhs))
135159
}

Tests/NimbleTests/Matchers/EqualTest.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,17 @@ final class EqualTest: XCTestCase {
158158
}
159159
}
160160

161+
// see: https://github.com/Quick/Nimble/issues/867
162+
func testOperatorEqualityWithImplicitMemberSyntax() {
163+
struct Xxx: Equatable {
164+
let value: Int
165+
}
166+
167+
let xxx = Xxx(value: 123)
168+
expect(xxx) == .init(value: 123)
169+
expect(xxx) != .init(value: 124)
170+
}
171+
161172
func testOperatorEqualityWithArrays() {
162173
let array1: [Int] = [1, 2, 3]
163174
let array2: [Int] = [1, 2, 3]

0 commit comments

Comments
 (0)