mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 13:25:00 +00:00
Fix test cases to match Cow variants (#14390)
Updates `without_trailing_slash` and `without_fragment` to separately match values against `Cow` variants. Closes #14350
This commit is contained in:
parent
d9f9ed4aec
commit
29fcd6faee
1 changed files with 17 additions and 10 deletions
|
@ -272,42 +272,49 @@ mod tests {
|
|||
fn without_fragment() {
|
||||
// Borrows a URL without a fragment
|
||||
let url = UrlString("https://example.com/path".into());
|
||||
assert_eq!(url.without_fragment(), Cow::Borrowed(&url));
|
||||
assert_eq!(&*url.without_fragment(), &url);
|
||||
assert!(matches!(url.without_fragment(), Cow::Borrowed(_)));
|
||||
|
||||
// Removes the fragment if present on the URL
|
||||
let url = UrlString("https://example.com/path?query#fragment".into());
|
||||
assert_eq!(
|
||||
url.without_fragment(),
|
||||
Cow::Owned(UrlString("https://example.com/path?query".into()))
|
||||
&*url.without_fragment(),
|
||||
&UrlString("https://example.com/path?query".into())
|
||||
);
|
||||
assert!(matches!(url.without_fragment(), Cow::Owned(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn without_trailing_slash() {
|
||||
// Borrows a URL without a slash
|
||||
let url = UrlString("https://example.com/path".into());
|
||||
assert_eq!(url.without_trailing_slash(), Cow::Borrowed(&url));
|
||||
assert_eq!(&*url.without_trailing_slash(), &url);
|
||||
assert!(matches!(url.without_trailing_slash(), Cow::Borrowed(_)));
|
||||
|
||||
// Removes the trailing slash if present on the URL
|
||||
let url = UrlString("https://example.com/path/".into());
|
||||
assert_eq!(
|
||||
url.without_trailing_slash(),
|
||||
Cow::Owned(UrlString("https://example.com/path".into()))
|
||||
&*url.without_trailing_slash(),
|
||||
&UrlString("https://example.com/path".into())
|
||||
);
|
||||
assert!(matches!(url.without_trailing_slash(), Cow::Owned(_)));
|
||||
|
||||
// Does not remove a trailing slash if it's the only path segment
|
||||
let url = UrlString("https://example.com/".into());
|
||||
assert_eq!(url.without_trailing_slash(), Cow::Borrowed(&url));
|
||||
assert_eq!(&*url.without_trailing_slash(), &url);
|
||||
assert!(matches!(url.without_trailing_slash(), Cow::Borrowed(_)));
|
||||
|
||||
// Does not remove a trailing slash if it's the only path segment with a missing scheme
|
||||
let url = UrlString("example.com/".into());
|
||||
assert_eq!(url.without_trailing_slash(), Cow::Borrowed(&url));
|
||||
assert_eq!(&*url.without_trailing_slash(), &url);
|
||||
assert!(matches!(url.without_trailing_slash(), Cow::Borrowed(_)));
|
||||
|
||||
// Removes the trailing slash when the scheme is missing
|
||||
let url = UrlString("example.com/path/".into());
|
||||
assert_eq!(
|
||||
url.without_trailing_slash(),
|
||||
Cow::Owned(UrlString("example.com/path".into()))
|
||||
&*url.without_trailing_slash(),
|
||||
&UrlString("example.com/path".into())
|
||||
);
|
||||
assert!(matches!(url.without_trailing_slash(), Cow::Owned(_)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue