use crate::soft_canonicalize;
#[cfg(feature = "anchored")]
use crate::anchored_canonicalize;
#[cfg(unix)]
#[test]
fn test_unix_multibyte_characters() {
use tempfile::TempDir;
let tmp = TempDir::new().expect("create tempdir");
let emoji_component = "🧐".repeat(50);
let emoji_path = tmp.path().join(emoji_component).join("file.txt");
let result = soft_canonicalize(&emoji_path);
assert!(
result.is_ok(),
"Unix should handle emoji paths: {:?}",
emoji_path
);
let cjk_component = "日本語".repeat(50);
let cjk_path = tmp.path().join(cjk_component).join("测试.txt");
let result = soft_canonicalize(&cjk_path);
assert!(
result.is_ok(),
"Unix should handle CJK paths: {:?}",
cjk_path
);
let mixed = format!(
"{}_{}_{}_{}",
"🎃".repeat(20),
"®".repeat(30),
"日".repeat(40),
"test"
);
let mixed_path = tmp.path().join(mixed).join("file.exe");
let result = soft_canonicalize(&mixed_path);
assert!(
result.is_ok(),
"Unix should handle mixed multibyte chars: {:?}",
mixed_path
);
}
#[cfg(unix)]
#[test]
fn test_unix_long_component_names() {
use tempfile::TempDir;
let tmp = TempDir::new().expect("create tempdir");
let component_250 = "a".repeat(250);
let path_250 = tmp.path().join(component_250).join("file.txt");
let result = soft_canonicalize(path_250);
assert!(result.is_ok(), "Should handle 250-byte component on Unix");
let component_255 = "b".repeat(255);
let path_255 = tmp.path().join(component_255).join("file.txt");
let result = soft_canonicalize(path_255);
assert!(result.is_ok(), "Should handle 255-byte component on Unix");
let component_300 = "c".repeat(300);
let path_300 = tmp.path().join(component_300).join("file.txt");
let result = soft_canonicalize(path_300);
match result {
Ok(_) => {
}
Err(e) => {
assert!(
e.kind() == std::io::ErrorKind::InvalidInput
|| e.kind() == std::io::ErrorKind::NotFound
|| e.kind() == std::io::ErrorKind::Other,
"Expected InvalidInput, NotFound, or Other for 300-byte component, got: {:?}",
e.kind()
);
}
}
}
#[cfg(unix)]
#[test]
fn test_unix_unicode_normalization() {
use tempfile::TempDir;
let tmp = TempDir::new().expect("create tempdir");
let composed = "café"; let path_composed = tmp.path().join(composed).join("file.txt");
let result_composed = soft_canonicalize(path_composed);
assert!(
result_composed.is_ok(),
"Unix should handle composed Unicode: {}",
composed
);
let decomposed = "café"; let path_decomposed = tmp.path().join(decomposed).join("file.txt");
let result_decomposed = soft_canonicalize(path_decomposed);
assert!(
result_decomposed.is_ok(),
"Unix should handle decomposed Unicode: {}",
decomposed
);
}
#[cfg(unix)]
#[test]
fn test_unix_maximum_path_depth() {
use tempfile::TempDir;
let tmp = TempDir::new().expect("create tempdir");
let mut current = tmp.path().to_path_buf();
for i in 0..100 {
current = current.join(format!("dir{}", i));
}
current = current.join("file.txt");
let result = soft_canonicalize(¤t);
assert!(
result.is_ok(),
"Unix should handle deeply nested paths (within PATH_MAX)"
);
}
#[test]
fn test_cross_platform_string_edge_cases() {
let result = soft_canonicalize("");
assert!(
result.is_err(),
"Empty path should be rejected on all platforms"
);
let null_path = "test\0file.txt";
let result = soft_canonicalize(null_path);
assert!(
result.is_err(),
"Null bytes should be rejected on all platforms"
);
}
#[cfg(feature = "anchored")]
#[test]
fn test_anchored_multibyte_cross_platform() {
use tempfile::TempDir;
let tmp = TempDir::new().expect("create tempdir");
let base = soft_canonicalize(tmp.path()).expect("canonicalize tempdir");
let emoji_path = "🧐/file.txt";
let result = anchored_canonicalize(&base, emoji_path);
assert!(
result.is_ok(),
"Anchored should handle emoji on all platforms: {}",
emoji_path
);
if let Ok(resolved) = result {
assert_eq!(
resolved,
base.join("🧐").join("file.txt"),
"Anchored emoji path should resolve correctly"
);
}
let cjk_path = "日本語/测试.txt";
let result = anchored_canonicalize(&base, cjk_path);
assert!(
result.is_ok(),
"Anchored should handle CJK on all platforms: {}",
cjk_path
);
let long_component = "a".repeat(200);
let long_path = format!("{}/file.txt", long_component);
let result = anchored_canonicalize(&base, long_path);
assert!(
result.is_ok(),
"Anchored should handle long components: {} bytes",
long_component.len()
);
}