use crate::soft_canonicalize;
use tempfile::tempdir;
#[test]
fn test_hybrid_optimization_compatibility() -> std::io::Result<()> {
let temp_dir = tempdir()?;
let base = temp_dir.path();
let existing_dir = base.join("existing");
std::fs::create_dir_all(&existing_dir)?;
std::fs::File::create(existing_dir.join("file"))?;
let existing_path = existing_dir.join("file");
let result = soft_canonicalize(&existing_path)?;
let std_result = std::fs::canonicalize(&existing_path)?;
#[cfg(not(feature = "dunce"))]
{
assert_eq!(result, std_result, "Without dunce: exact match");
}
#[cfg(feature = "dunce")]
{
#[cfg(windows)]
{
let result_str = result.to_string_lossy();
let std_str = std_result.to_string_lossy();
assert!(!result_str.starts_with(r"\\?\"), "dunce should simplify");
assert!(std_str.starts_with(r"\\?\"), "std returns UNC");
}
#[cfg(not(windows))]
{
assert_eq!(result, std_result);
}
}
let non_existing_path = base.join("non_existing/file.txt");
let result = soft_canonicalize(non_existing_path)?;
assert!(result.is_absolute());
assert!(result.to_string_lossy().contains("non_existing"));
Ok(())
}