Skip to content

Commit ab7f6fc

Browse files
committed
Add tests
1 parent 3e72c19 commit ab7f6fc

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/tests.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,49 @@ fn issue_124() {
301301
let url: Url = "file:..".parse().unwrap();
302302
assert_eq!(url.path().unwrap(), [""]);
303303
}
304+
305+
#[test]
306+
fn relative_scheme_data_equality() {
307+
use std::hash::{Hash, Hasher, SipHasher};
308+
309+
fn check_eq(a: &Url, b: &Url) {
310+
assert_eq!(a, b);
311+
312+
let mut h1 = SipHasher::new();
313+
a.hash(&mut h1);
314+
let mut h2 = SipHasher::new();
315+
b.hash(&mut h2);
316+
assert_eq!(h1.finish(), h2.finish());
317+
}
318+
319+
fn url(s: &str) -> Url {
320+
let rv = s.parse().unwrap();
321+
check_eq(&rv, &rv);
322+
rv
323+
}
324+
325+
// Doesn't care if default port is given.
326+
let a: Url = url("https://example.com/");
327+
let b: Url = url("https://example.com:443/");
328+
check_eq(&a, &b);
329+
330+
// Different ports
331+
let a: Url = url("http://example.com/");
332+
let b: Url = url("http://example.com:8080/");
333+
assert!(a != b);
334+
335+
// Different scheme
336+
let a: Url = url("http://example.com/");
337+
let b: Url = url("https://example.com/");
338+
assert!(a != b);
339+
340+
// Different host
341+
let a: Url = url("http://foo.com/");
342+
let b: Url = url("http://bar.com/");
343+
assert!(a != b);
344+
345+
// Missing path, automatically substituted. Semantically the same.
346+
let a: Url = url("http://foo.com");
347+
let b: Url = url("http://foo.com/");
348+
check_eq(&a, &b);
349+
}

0 commit comments

Comments
 (0)