Skip to content

Commit be4809e

Browse files
committed
Increase Origin test coverage
Add unit tests for unicode_serialization() and is_tuple(). New test coverage: || ../idna/src/lib.rs: 4/6 +33.33333333333333% || ../idna/src/uts46.rs: 158/299 +2.341137123745818% || src/origin.rs: 32/37 +40.54054054054054% || src/parser.rs: 681/848 +0.1179245283018826%
1 parent 837538c commit be4809e

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

url/tests/unit.rs

Lines changed: 46 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,51 @@ 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 unicode_urls = [
537+
"http://😅.com",
538+
"ftp://🙂.com"
539+
];
540+
for unicode_url in &unicode_urls {
541+
let origin = Url::parse(unicode_url).unwrap().origin();
542+
assert_eq!(origin.unicode_serialization(), *unicode_url);
543+
}
544+
545+
let ascii_origins = [
546+
Url::parse("http://example.net/").unwrap().origin(),
547+
Url::parse("http://example.net:80/").unwrap().origin(),
548+
Url::parse("http://example.net:81/").unwrap().origin(),
549+
Url::parse("http://example.net").unwrap().origin(),
550+
Url::parse("http://example.net/hello").unwrap().origin(),
551+
Url::parse("https://example.net").unwrap().origin(),
552+
Url::parse("ftp://example.net").unwrap().origin(),
553+
Url::parse("file://example.net").unwrap().origin(),
554+
Url::parse("http://user@example.net/").unwrap().origin(),
555+
Url::parse("http://user:pass@example.net/")
556+
.unwrap()
557+
.origin(),
558+
Url::parse("http://127.0.0.1").unwrap().origin(),
559+
];
560+
for ascii_origin in &ascii_origins {
561+
assert_eq!(ascii_origin.ascii_serialization(), ascii_origin.unicode_serialization());
562+
}
563+
}
564+
520565
#[test]
521566
fn test_windows_unc_path() {
522567
if !cfg!(windows) {

0 commit comments

Comments
 (0)