From 9ebd94cb93dad2e9fe92fe7eb56576ffff038142 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 31 Dec 2024 14:16:08 -0500 Subject: [PATCH] Add tests for `UrlString` methods (#10256) --- crates/uv-distribution-types/src/file.rs | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/crates/uv-distribution-types/src/file.rs b/crates/uv-distribution-types/src/file.rs index 5336a1b7f..10de4a9c6 100644 --- a/crates/uv-distribution-types/src/file.rs +++ b/crates/uv-distribution-types/src/file.rs @@ -275,3 +275,35 @@ pub enum ToUrlError { path: String, }, } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn base_str() { + let url = UrlString("https://example.com/path?query#fragment".to_string()); + assert_eq!(url.base_str(), "https://example.com/path"); + + let url = UrlString("https://example.com/path#fragment".to_string()); + assert_eq!(url.base_str(), "https://example.com/path"); + + let url = UrlString("https://example.com/path".to_string()); + assert_eq!(url.base_str(), "https://example.com/path"); + } + + #[test] + fn without_fragment() { + let url = UrlString("https://example.com/path?query#fragment".to_string()); + assert_eq!( + url.without_fragment(), + UrlString("https://example.com/path?query".to_string()) + ); + + let url = UrlString("https://example.com/path#fragment".to_string()); + assert_eq!(url.base_str(), "https://example.com/path"); + + let url = UrlString("https://example.com/path".to_string()); + assert_eq!(url.base_str(), "https://example.com/path"); + } +}