From a46da536ea630878f73788ff1bb46c00fca7ee38 Mon Sep 17 00:00:00 2001 From: Rachel Brindle Date: Thu, 12 Dec 2024 07:36:40 -0800 Subject: [PATCH] add an explicit test that NSObject equality works --- Tests/NimbleTests/Matchers/EqualTest.swift | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Tests/NimbleTests/Matchers/EqualTest.swift b/Tests/NimbleTests/Matchers/EqualTest.swift index 504a82827..07646f5f1 100644 --- a/Tests/NimbleTests/Matchers/EqualTest.swift +++ b/Tests/NimbleTests/Matchers/EqualTest.swift @@ -182,6 +182,29 @@ final class EqualTest: XCTestCase { // swiftlint:disable:this type_body_length expect { 1 as NSNumber }.to(equal(1 as NSNumber)) } + func testCustomNSObjectEquality() { + final class SomeObject: NSObject { + let id: Int + + init(id: Int) { + self.id = id + } + + override func isEqual(_ object: Any?) -> Bool { + guard let rhs = object as? SomeObject else { + return false + } + + return self.id == rhs.id + } + } + + expect(SomeObject(id: 1)).to(equal(SomeObject(id: 1))) + let obj1 = SomeObject(id: 1) + expect(obj1).to(equal(obj1)) + expect(SomeObject(id: 1)).toNot(equal(SomeObject(id: 2))) + } + func testOperatorEquality() { expect("foo") == "foo" expect("foo") != "bar"