#[cfg(feature = "virtual-path")]
use crate::VirtualRoot;
#[cfg(feature = "virtual-path")]
#[test]
fn f7a_virtual_join_navigates_through_sanitized_character_dir() {
use std::fs;
let td = tempfile::tempdir().unwrap();
let real_dir = td.path().join("foo\u{0085}bar");
fs::create_dir(&real_dir).unwrap();
fs::write(real_dir.join("child.txt"), b"hello").unwrap();
let vroot: VirtualRoot = VirtualRoot::try_new(td.path()).unwrap();
let parent_vp = vroot
.virtual_join("foo\u{0085}bar")
.expect("virtual_join to sanitized-char dir should succeed");
let child_vp = parent_vp
.virtual_join("child.txt")
.expect("virtual_join('child.txt') from sanitized-char parent should succeed");
let system_display = child_vp.as_unvirtual().strictpath_display().to_string();
assert!(
system_display.contains("foo\u{0085}bar"),
"virtual_join must navigate through the original (unsanitized) directory name; \
got system path: {system_display:?}"
);
let content = child_vp
.read_to_string()
.expect("child.txt must be readable through the correct system path");
assert_eq!(content, "hello");
}
#[cfg(feature = "virtual-path")]
#[test]
fn f7b_display_still_sanitizes_after_navigation_fix() {
use std::fs;
let td = tempfile::tempdir().unwrap();
let real_dir = td.path().join("foo\u{0085}bar");
fs::create_dir(&real_dir).unwrap();
fs::write(real_dir.join("child.txt"), b"x").unwrap();
let vroot: VirtualRoot = VirtualRoot::try_new(td.path()).unwrap();
let parent_vp = vroot.virtual_join("foo\u{0085}bar").unwrap();
let display = parent_vp.virtualpath_display().to_string();
assert!(
!display.contains('\u{0085}'),
"virtualpath_display must NOT expose U+0085 NEL after the F7 fix: {display:?}"
);
assert!(
display.contains("foo_bar"),
"virtualpath_display should show sanitized 'foo_bar': {display:?}"
);
}
#[cfg(feature = "virtual-path")]
#[test]
fn f7c_virtualpath_parent_round_trip_preserves_original_chars() {
use std::fs;
let td = tempfile::tempdir().unwrap();
let real_dir = td.path().join("foo\u{0085}bar");
fs::create_dir(&real_dir).unwrap();
fs::write(real_dir.join("child.txt"), b"x").unwrap();
let vroot: VirtualRoot = VirtualRoot::try_new(td.path()).unwrap();
let parent_vp = vroot.virtual_join("foo\u{0085}bar").unwrap();
let child_vp = parent_vp.virtual_join("child.txt").unwrap();
let recovered_parent = child_vp
.virtualpath_parent()
.expect("virtualpath_parent should succeed")
.expect("child has a parent");
let parent_system = recovered_parent
.as_unvirtual()
.strictpath_display()
.to_string();
assert!(
parent_system.contains("foo\u{0085}bar"),
"virtualpath_parent must recover the real directory name: {parent_system:?}"
);
}