From 522e1455c874314437d3c90568b74954b4488198 Mon Sep 17 00:00:00 2001 From: Sean Kim <40130483+theskim@users.noreply.github.com> Date: Wed, 18 Dec 2024 12:30:33 -0500 Subject: [PATCH] Improve testing for host, path, query, hash when mutating path --- url/tests/unit.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/url/tests/unit.rs b/url/tests/unit.rs index 2f0c0e92..e186431a 100644 --- a/url/tests/unit.rs +++ b/url/tests/unit.rs @@ -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(); +}