use std::path::Path;
pub(crate) fn display_path(path: &Path) -> String {
let text = path.to_string_lossy();
if let Some(share) = text.strip_prefix(r"\\?\UNC\") {
return format!(r"\\{share}");
}
text.strip_prefix(r"\\?\").unwrap_or(&text).to_string()
}
#[cfg(test)]
#[cfg_attr(coverage_nightly, coverage(off))]
mod tests {
use std::path::PathBuf;
use super::*;
#[test]
fn strips_the_extended_length_prefix() {
assert_eq!(display_path(&PathBuf::from(r"\\?\C:\Source")), r"C:\Source");
}
#[test]
fn restores_the_network_share_form() {
assert_eq!(
display_path(&PathBuf::from(r"\\?\UNC\server\share\work")),
r"\\server\share\work"
);
}
#[test]
fn leaves_an_ordinary_path_alone() {
assert_eq!(display_path(&PathBuf::from(r"C:\Source")), r"C:\Source");
assert_eq!(display_path(&PathBuf::from("/work")), "/work");
}
}