-
Notifications
You must be signed in to change notification settings - Fork 100
Print object identity in diff #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| extension ObjectIdentifier: CustomDumpStringConvertible { | ||
| public var customDumpDescription: String { | ||
| self.debugDescription | ||
| .replacingOccurrences(of: "0x0*", with: "0x", options: .regularExpression) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shortens ObjectIdentifier(0x00000000000deadbeef) to ObjectIdentifier(0xdeadbeef).
| let showObjectIdentifiers = lhsItem != rhsItem | ||
| && isMirrorEqual(Array(lhsMirror.children), Array(rhsMirror.children)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll only diff/print object identifiers if all the exposed properties are equal. This should avoid noise in classes where are objects are equatable across identity.
Sources/CustomDump/Diff.swift
Outdated
| _ transform: (inout Mirror.Child, Int) -> Void = { _, _ in } | ||
| ) { | ||
| guard !lhsMirror.children.isEmpty || !rhsMirror.children.isEmpty | ||
| guard !isMirrorEqual(Array(lhsMirror.children), Array(rhsMirror.children)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if there's a more performant approach...
| guard !isMirrorEqual(Array(lhsMirror.children), Array(rhsMirror.children)) | ||
| else { | ||
| print( | ||
| "// Not equal but no difference detected:" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll now print a message when no difference is detected.
| """ | ||
| // Not equal but no difference detected: | ||
| - NeverEqualUser(…) | ||
| + NeverEqualUser(…) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could expand the properties here to aid a bit more in debugging...
NSObjects are equatable by object identity by default, which can lead todiffreturning a confusing string with no insertions/removals when all properties look the same, as brought up in this TCA discussion. This PR attempts to surface the object identity mismatch when everything else is the same.