Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

amomchilov
Copy link

And added related tests, improved Equatable tests, and fixed up some minor grammar mistakes

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).
@amomchilov
Copy link
Author

@cockscomb Hi Hiroki, could you please review this PR?

Copy link
Owner

@cockscomb cockscomb left a 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
Copy link
Owner

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.

Copy link
Owner

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())
    }
}

Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants