Skip to content

Commit 12310f2

Browse files
authored
Merge pull request #702 from BramBonne/origin_tests
Increase Origin test coverage
2 parents 837538c + 90e4f50 commit 12310f2

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

url/tests/unit.rs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::borrow::Cow;
1212
use std::cell::{Cell, RefCell};
1313
use std::net::{Ipv4Addr, Ipv6Addr};
1414
use std::path::{Path, PathBuf};
15-
use url::{form_urlencoded, Host, Url};
15+
use url::{form_urlencoded, Host, Origin, Url};
1616

1717
#[test]
1818
fn size() {
@@ -517,6 +517,56 @@ fn test_origin_hash() {
517517
assert_ne!(hash(&opaque_origin), hash(&other_opaque_origin));
518518
}
519519

520+
#[test]
521+
fn test_origin_blob_equality() {
522+
let origin = &Url::parse("http://example.net/").unwrap().origin();
523+
let blob_origin = &Url::parse("blob:http://example.net/").unwrap().origin();
524+
525+
assert_eq!(origin, blob_origin);
526+
}
527+
528+
#[test]
529+
fn test_origin_opaque() {
530+
assert!(!Origin::new_opaque().is_tuple());
531+
assert!(!&Url::parse("blob:malformed//").unwrap().origin().is_tuple())
532+
}
533+
534+
#[test]
535+
fn test_origin_unicode_serialization() {
536+
let data = [
537+
("http://😅.com", "http://😅.com"),
538+
("ftp://😅:🙂@🙂.com", "ftp://🙂.com"),
539+
("https://user@😅.com", "https://😅.com"),
540+
("http://😅.🙂:40", "http://😅.🙂:40"),
541+
];
542+
for &(unicode_url, expected_serialization) in &data {
543+
let origin = Url::parse(unicode_url).unwrap().origin();
544+
assert_eq!(origin.unicode_serialization(), *expected_serialization);
545+
}
546+
547+
let ascii_origins = [
548+
Url::parse("http://example.net/").unwrap().origin(),
549+
Url::parse("http://example.net:80/").unwrap().origin(),
550+
Url::parse("http://example.net:81/").unwrap().origin(),
551+
Url::parse("http://example.net").unwrap().origin(),
552+
Url::parse("http://example.net/hello").unwrap().origin(),
553+
Url::parse("https://example.net").unwrap().origin(),
554+
Url::parse("ftp://example.net").unwrap().origin(),
555+
Url::parse("file://example.net").unwrap().origin(),
556+
Url::parse("http://user@example.net/").unwrap().origin(),
557+
Url::parse("http://user:pass@example.net/")
558+
.unwrap()
559+
.origin(),
560+
Url::parse("http://127.0.0.1").unwrap().origin(),
561+
];
562+
for ascii_origin in &ascii_origins {
563+
assert_eq!(
564+
ascii_origin.ascii_serialization(),
565+
ascii_origin.unicode_serialization()
566+
);
567+
}
568+
}
569+
520570
#[test]
521571
fn test_windows_unc_path() {
522572
if !cfg!(windows) {

0 commit comments

Comments
 (0)