windows: Fix tests on Windows (#22616)
Release Notes: - N/A --------- Co-authored-by: Mikayla <mikayla.c.maki@gmail.com>
This commit is contained in:
parent
c252b5db16
commit
74c4dbd237
56 changed files with 1540 additions and 856 deletions
|
@ -23,6 +23,7 @@ pub trait PathExt {
|
|||
fn compact(&self) -> PathBuf;
|
||||
fn icon_stem_or_suffix(&self) -> Option<&str>;
|
||||
fn extension_or_hidden_file_name(&self) -> Option<&str>;
|
||||
fn to_sanitized_string(&self) -> String;
|
||||
fn try_from_bytes<'a>(bytes: &'a [u8]) -> anyhow::Result<Self>
|
||||
where
|
||||
Self: From<&'a Path>,
|
||||
|
@ -94,6 +95,20 @@ impl<T: AsRef<Path>> PathExt for T {
|
|||
|
||||
self.as_ref().file_name()?.to_str()?.split('.').last()
|
||||
}
|
||||
|
||||
/// Returns a sanitized string representation of the path.
|
||||
/// Note, on Windows, this assumes that the path is a valid UTF-8 string and
|
||||
/// is not a UNC path.
|
||||
fn to_sanitized_string(&self) -> String {
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
self.as_ref().to_string_lossy().replace("/", "\\")
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
self.as_ref().to_string_lossy().to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Due to the issue of UNC paths on Windows, which can cause bugs in various parts of Zed, introducing this `SanitizedPath`
|
||||
|
@ -115,6 +130,17 @@ impl SanitizedPath {
|
|||
self.0.to_string_lossy().to_string()
|
||||
}
|
||||
|
||||
pub fn to_glob_string(&self) -> String {
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
self.0.to_string_lossy().replace("/", "\\")
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
self.0.to_string_lossy().to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn join(&self, path: &Self) -> Self {
|
||||
self.0.join(&path.0).into()
|
||||
}
|
||||
|
@ -448,14 +474,6 @@ pub fn compare_paths(
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub fn replace_path_separator(path: &str) -> String {
|
||||
#[cfg(target_os = "windows")]
|
||||
return path.replace("/", std::path::MAIN_SEPARATOR_STR);
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
return path.to_string();
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue