Skip to content

Commit 6de3456

Browse files
authored
add an explicit test that NSObject equality works (#1181)
1 parent fd4a97e commit 6de3456

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Tests/NimbleTests/Matchers/EqualTest.swift

+23
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,29 @@ final class EqualTest: XCTestCase { // swiftlint:disable:this type_body_length
182182
expect { 1 as NSNumber }.to(equal(1 as NSNumber))
183183
}
184184

185+
func testCustomNSObjectEquality() {
186+
final class SomeObject: NSObject {
187+
let id: Int
188+
189+
init(id: Int) {
190+
self.id = id
191+
}
192+
193+
override func isEqual(_ object: Any?) -> Bool {
194+
guard let rhs = object as? SomeObject else {
195+
return false
196+
}
197+
198+
return self.id == rhs.id
199+
}
200+
}
201+
202+
expect(SomeObject(id: 1)).to(equal(SomeObject(id: 1)))
203+
let obj1 = SomeObject(id: 1)
204+
expect(obj1).to(equal(obj1))
205+
expect(SomeObject(id: 1)).toNot(equal(SomeObject(id: 2)))
206+
}
207+
185208
func testOperatorEquality() {
186209
expect("foo") == "foo"
187210
expect("foo") != "bar"

0 commit comments

Comments
 (0)