Skip to content

Commit ea2342e

Browse files
authored
Merge pull request #705 from BramBonne/test-quirks
Increase quirks test coverage
2 parents d85ac13 + 548c15b commit ea2342e

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

url/tests/unit.rs

+37
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,43 @@ fn test_set_ip_host() {
683683
assert_eq!(url.host_str(), Some("[::1]"));
684684
}
685685

686+
#[test]
687+
fn test_set_href() {
688+
use url::quirks::set_href;
689+
690+
let mut url = Url::parse("https://existing.url").unwrap();
691+
692+
assert!(set_href(&mut url, "mal//formed").is_err());
693+
694+
assert!(set_href(
695+
&mut url,
696+
"https://user:[email protected]:9742/path/file.ext?key=val&key2=val2#fragment"
697+
)
698+
.is_ok());
699+
assert_eq!(
700+
url,
701+
Url::parse("https://user:[email protected]:9742/path/file.ext?key=val&key2=val2#fragment")
702+
.unwrap()
703+
);
704+
}
705+
706+
#[test]
707+
fn test_domain_encoding_quirks() {
708+
use url::quirks::{domain_to_ascii, domain_to_unicode};
709+
710+
let data = [
711+
("http://example.com", "", ""),
712+
("😅.🙂", "xn--j28h.xn--938h", "😅.🙂"),
713+
("example.com", "example.com", "example.com"),
714+
("mailto:[email protected]", "", ""),
715+
];
716+
717+
for url in &data {
718+
assert_eq!(domain_to_ascii(url.0), url.1);
719+
assert_eq!(domain_to_unicode(url.0), url.2);
720+
}
721+
}
722+
686723
#[test]
687724
fn test_windows_unc_path() {
688725
if !cfg!(windows) {

0 commit comments

Comments
 (0)