Skip to content

Commit

Permalink
add an explicit test that NSObject equality works (#1181)
Browse files Browse the repository at this point in the history
  • Loading branch information
younata authored Dec 12, 2024
1 parent fd4a97e commit 6de3456
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Tests/NimbleTests/Matchers/EqualTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6de3456

Please sign in to comment.