#![cfg(windows)]
use crate::soft_canonicalize;
#[test]
fn verify_format_without_dunce_is_unc() {
let result = soft_canonicalize(r"C:\Test\Path").unwrap();
#[cfg(not(feature = "dunce"))]
{
let result_str = result.to_string_lossy();
assert!(
result_str.starts_with(r"\\?\"),
"Without dunce feature, output MUST have UNC prefix. Got: {}",
result_str
);
assert_eq!(result, std::path::PathBuf::from(r"\\?\C:\Test\Path"));
}
#[cfg(feature = "dunce")]
{
let _ = result;
}
}
#[cfg(feature = "dunce")]
#[test]
fn verify_format_with_dunce_simplifies_safe_paths() {
let result = soft_canonicalize(r"C:\Test\Path").unwrap();
let result_str = result.to_string_lossy();
assert!(
!result_str.starts_with(r"\\?\"),
"With dunce feature, safe paths should NOT have UNC prefix. Got: {}",
result_str
);
assert!(
result_str.starts_with(r"C:\"),
"Expected simplified format C:\\..., got: {}",
result_str
);
}
#[cfg(feature = "dunce")]
#[test]
fn verify_format_with_dunce_preserves_unsafe_long_paths() {
let long_path = format!(r"C:\{}\file.txt", "a".repeat(300));
let result = soft_canonicalize(long_path).unwrap();
let result_str = result.to_string_lossy();
assert!(
result_str.starts_with(r"\\?\"),
"With dunce feature, long paths should preserve UNC prefix. Got: {}",
result_str
);
}
#[cfg(feature = "dunce")]
#[test]
fn verify_format_with_dunce_resolves_dotdot_then_simplifies() {
use tempfile::TempDir;
let temp_dir = TempDir::new().unwrap();
let test_path = temp_dir
.path()
.join("a")
.join("..")
.join("b")
.join("file.txt");
let result = soft_canonicalize(test_path).unwrap();
let result_str = result.to_string_lossy();
assert!(
!result_str.starts_with(r"\\?\"),
"With dunce feature, resolved safe paths should be simplified. Got: {}",
result_str
);
}
#[cfg(feature = "dunce")]
#[test]
fn verify_format_with_dunce_preserves_reserved_names() {
let result = soft_canonicalize(r"C:\CON\file.txt").unwrap();
let result_str = result.to_string_lossy();
assert!(
result_str.starts_with(r"\\?\"),
"With dunce feature, paths with reserved names should preserve UNC prefix. Got: {}",
result_str
);
}