Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dc26bfd

Browse files
committedDec 18, 2024·
Improve testing for host, path, query, hash when mutating path
1 parent f122364 commit dc26bfd

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
 

‎url/tests/unit.rs

+32
Original file line numberDiff line numberDiff line change
@@ -1471,3 +1471,35 @@ fn test_can_be_a_base_with_path_segments_mut() {
14711471
.collect();
14721472
assert_eq!(segments, vec!["", "not-a-host"]);
14731473
}
1474+
1475+
#[test]
1476+
fn test_valid_indices_after_set_path() {
1477+
// Testing everything
1478+
let mut url = Url::parse("moz:/").unwrap();
1479+
assert!(!url.cannot_be_a_base());
1480+
1481+
url.set_path("/.//p");
1482+
url.set_host(Some("host")).unwrap();
1483+
url.set_query(Some("query"));
1484+
url.set_fragment(Some("frag"));
1485+
assert_eq!(url.as_str(), "moz://host//p?query#frag");
1486+
assert_eq!(url.host(), Some(Host::Domain("host")));
1487+
assert_eq!(url.path(), "//p");
1488+
assert_eq!(url.query(), Some("query"));
1489+
assert_eq!(url.fragment(), Some("frag"));
1490+
url.check_invariants().unwrap();
1491+
1492+
url = Url::parse("moz:/.//").unwrap();
1493+
assert!(!url.cannot_be_a_base());
1494+
1495+
url.set_path("p");
1496+
url.set_host(Some("host")).unwrap();
1497+
url.set_query(Some("query"));
1498+
url.set_fragment(Some("frag"));
1499+
assert_eq!(url.as_str(), "moz://host/p?query#frag");
1500+
assert_eq!(url.host(), Some(Host::Domain("host")));
1501+
assert_eq!(url.path(), "/p");
1502+
assert_eq!(url.query(), Some("query"));
1503+
assert_eq!(url.fragment(), Some("frag"));
1504+
url.check_invariants().unwrap();
1505+
}

0 commit comments

Comments
 (0)
Please sign in to comment.