Skip to content

Commit

Permalink
Improve testing for host, path, query, hash when mutating path
Browse files Browse the repository at this point in the history
  • Loading branch information
theskim committed Dec 18, 2024
1 parent f122364 commit dc26bfd
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions url/tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1471,3 +1471,35 @@ fn test_can_be_a_base_with_path_segments_mut() {
.collect();
assert_eq!(segments, vec!["", "not-a-host"]);
}

#[test]
fn test_valid_indices_after_set_path() {
// Testing everything
let mut url = Url::parse("moz:/").unwrap();
assert!(!url.cannot_be_a_base());

url.set_path("/.//p");
url.set_host(Some("host")).unwrap();
url.set_query(Some("query"));
url.set_fragment(Some("frag"));
assert_eq!(url.as_str(), "moz://host//p?query#frag");
assert_eq!(url.host(), Some(Host::Domain("host")));
assert_eq!(url.path(), "//p");
assert_eq!(url.query(), Some("query"));
assert_eq!(url.fragment(), Some("frag"));
url.check_invariants().unwrap();

url = Url::parse("moz:/.//").unwrap();
assert!(!url.cannot_be_a_base());

url.set_path("p");
url.set_host(Some("host")).unwrap();
url.set_query(Some("query"));
url.set_fragment(Some("frag"));
assert_eq!(url.as_str(), "moz://host/p?query#frag");
assert_eq!(url.host(), Some(Host::Domain("host")));
assert_eq!(url.path(), "/p");
assert_eq!(url.query(), Some("query"));
assert_eq!(url.fragment(), Some("frag"));
url.check_invariants().unwrap();
}

0 comments on commit dc26bfd

Please sign in to comment.