-
Notifications
You must be signed in to change notification settings - Fork 22
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
Added conformance to Hashable #19
base: master
Are you sure you want to change the base?
Conversation
Before it was performing the same job as `testInitialize_MIMEType` and `testInitialize_filenameExtension`. Now, it actually tests the requirements of the Equatable protocol (and equivalence relations, more generally).
@cockscomb Hi Hiroki, could you please review this PR? |
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.
It's a good idea to comply with Hashable. But I think it's a little difficult.
// `Equatable` are logically valid, we need to assert that `==` and `UTTypeEqual` behave | ||
// equally | ||
let expected = UTTypeEqual(lhs.utiString as CFString, rhs.utiString as CFString) | ||
let actual = lhs.utiString == rhs.utiString |
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.
A quick check shows that UTTypeEqual
is not a simple string match. It seems to be case-insensitive.
UTTypeEqual("public.image" as CFString, "public.image" as CFString) // true
UTTypeEqual("public.image" as CFString, "PUBLIC.IMAGE" as CFString) // true
However, I couldn't find any documentation on how it was implemented.
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.
Getting a canonical identifier from the declaration may work. You also need to fall back to utiString
for dynamic UTI.
extension UTI: Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(self.declaration.identifier ?? self.utiString.lowercased())
}
}
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.
Hey, thanks for getting back on this! Really busy right now, but I'll fix these up when I get a chance and repsuh!
And added related tests, improved Equatable tests, and fixed up some minor grammar mistakes