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

Implement `Hash` for `Origin` (fix #302) #321

Merged
merged 1 commit into from Jun 3, 2017

Conversation

Projects
None yet
8 participants
@cGuille
Copy link
Contributor

cGuille commented May 5, 2017

Hello,

I'm a Rust / Open Source beginner, so just explain if anything is wrong. :-)

I am giving a try at issue #302. I just derived the Hash for the Origin type.

I have zero experience with testing in Rust so I just tried to demonstrate that it works, but I do not know how to write a good test for this.

What should I do now?


This change is Reviewable

@skade

This comment has been minimized.

Copy link

skade commented May 5, 2017

@cGuille Wait for one of the maintainers to provide review :). Most maintainers of the URL crate live in the US, so this might take until later.

Ignore the nightly error in the linked travis test suite, rust nightly is currently broken, not this lib.

@emilio

This comment has been minimized.

Copy link
Member

emilio commented May 5, 2017

@SimonSapin is french fwiw, hopefully he can take a look soon-ish.

Can you test also that opaque origins get different hashes? (It's trivial, but worth having that in the test-suite too).

@cGuille

This comment has been minimized.

Copy link
Contributor Author

cGuille commented May 5, 2017

Hello,

There is actually no hurry at all. :-)

I am OK with adding more tests ; I will just have to figure out how.
I do not like using HashMap to indirectly test the Hash trait ; it would be nice to have someone else's opinion about this.

@SimonSapin

This comment has been minimized.

Copy link
Member

SimonSapin commented May 5, 2017

@skade, unfortunately, most of the maintainers of the url crate are me :) I’m usually in UTC+1~2.

@cGuille You can hash without a hashmap like so:

use std::collections::hash_map::DefaultHasher;
use std::hash::Hash;

fn hash<T: Hash>(value: T) -> u64 {
    let mut hasher = DefaultHasher::new();
    value.hash(&mut hasher);
    hasher.finish()
}

To make the test more interesting, you could use different URLs that have the same origin. Please also test that hashing is consistent with == equality.

Thanks!

@cGuille cGuille force-pushed the cGuille:impl-hash-trait-for-origin branch from 894bc2f to 459904f May 5, 2017

@cGuille

This comment has been minimized.

Copy link
Contributor Author

cGuille commented May 5, 2017

Thank you!

I updated the PR to test hash values directly instead of using HashMap, but I do not know how to test that hashing is consistent with equality. Do you have something in mind?
Should I just check that equalities of the origins in my test are the same as the equalities of their hashes?

@SimonSapin

This comment has been minimized.

Copy link
Member

SimonSapin commented May 5, 2017

Test that things that compare equal with == have the same hash. Test that things that compare unequal have a different hash. The latter is not guaranteed because there could be hashing collisions, but it is unlikely enough that it’s alright to test in a couple fixed-input test cases.

@cGuille cGuille force-pushed the cGuille:impl-hash-trait-for-origin branch from 459904f to 38104b5 May 5, 2017

@cGuille

This comment has been minimized.

Copy link
Contributor Author

cGuille commented May 5, 2017

What do you think about this? Are there enough URL samples?
Edit: I also added tests with opaque origins, as @emilio suggested.

@cGuille cGuille force-pushed the cGuille:impl-hash-trait-for-origin branch from 38104b5 to dbe1980 May 5, 2017

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented May 9, 2017

☔️ The latest upstream changes (presumably #306) made this pull request unmergeable. Please resolve the merge conflicts.

@cGuille cGuille force-pushed the cGuille:impl-hash-trait-for-origin branch from e224f8c to 7e9c87d May 10, 2017

@cGuille

This comment has been minimized.

Copy link
Contributor Author

cGuille commented May 10, 2017

I solved the conflict with master and rebased the branch upon it.

Tell me if there is anything left to do regarding this PR.

@dtolnay
Copy link

dtolnay left a comment

Looks good to me. All of the feedback so far has been addressed.

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented May 20, 2017

☔️ The latest upstream changes (presumably #344) made this pull request unmergeable. Please resolve the merge conflicts.

@cGuille cGuille force-pushed the cGuille:impl-hash-trait-for-origin branch from 7e9c87d to 4260325 May 26, 2017

@cGuille

This comment has been minimized.

Copy link
Contributor Author

cGuille commented May 26, 2017

I rebased upon master to solve this second conflict.

Can this be merged?

@cGuille

This comment has been minimized.

Copy link
Contributor Author

cGuille commented May 29, 2017

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Jun 3, 2017

@bors-servo r+

bors-servo probably doesn't listen to me...

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented Jun 3, 2017

@brson: 🔑 Insufficient privileges: Not in reviewers

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Jun 3, 2017

Sorry for the delay @cGuille !

@cbrewster

This comment has been minimized.

Copy link
Member

cbrewster commented Jun 3, 2017

@bors-servo r=brson

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented Jun 3, 2017

📌 Commit 4260325 has been approved by brson

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented Jun 3, 2017

⌛️ Testing commit 4260325 with merge 2641e36...

bors-servo added a commit that referenced this pull request Jun 3, 2017

Auto merge of #321 - cGuille:impl-hash-trait-for-origin, r=brson
Implement `Hash` for `Origin` (fix #302)

Hello,

I'm a Rust / Open Source beginner, so just explain if anything is wrong. :-)

I am giving a try at issue #302. I just derived the `Hash` for the `Origin` type.

I have zero experience with testing in Rust so I just tried to demonstrate that it works, but I do not know how to write a good test for this.

What should I do now?

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-url/321)
<!-- Reviewable:end -->
@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented Jun 3, 2017

☀️ Test successful - status-travis
Approved by: brson
Pushing 2641e36 to master...

@bors-servo bors-servo merged commit 4260325 into servo:master Jun 3, 2017

3 of 4 checks passed

code-review/reviewable 2 files left
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

@cGuille cGuille deleted the cGuille:impl-hash-trait-for-origin branch Jul 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.