#[cfg(test)]
mod display_methods_tests {
use crate::PathBoundary;
#[cfg(feature = "virtual-path")]
use crate::VirtualRoot;
#[test]
fn test_restriction_path_strictpath_display() {
let temp = tempfile::tempdir().unwrap();
let temp_dir: PathBoundary = PathBoundary::try_new(temp.path()).unwrap();
let display = temp_dir.strictpath_display();
let display_string = format!("{display}");
assert!(!display_string.is_empty());
#[cfg(windows)]
assert!(display_string.to_lowercase().contains("temp") || display_string.contains("tmp"));
#[cfg(unix)]
assert!(display_string.contains("tmp"));
}
#[test]
#[cfg(feature = "virtual-path")]
fn test_virtual_root_display() {
let temp = tempfile::tempdir().unwrap();
let vroot: VirtualRoot = VirtualRoot::try_new(temp.path()).unwrap();
let restricted_display = vroot.as_unvirtual().strictpath_display();
let restricted_display_string = format!("{restricted_display}");
assert!(!restricted_display_string.is_empty());
#[cfg(windows)]
assert!(
restricted_display_string.to_lowercase().contains("temp")
|| restricted_display_string.contains("tmp")
);
#[cfg(unix)]
assert!(restricted_display_string.contains("tmp"));
}
#[test]
#[cfg(feature = "virtual-path")]
fn test_display_methods_consistency() {
let temp = tempfile::tempdir().unwrap();
let temp_dir: PathBoundary = PathBoundary::try_new(temp.path()).unwrap();
let vroot: VirtualRoot = VirtualRoot::try_new(temp.path()).unwrap();
let temp_dir_display = temp_dir.strictpath_display().to_string();
let path_display = temp.path().canonicalize().unwrap().display().to_string();
assert_eq!(temp_dir_display, path_display);
let vroot_restricted_display = vroot.as_unvirtual().strictpath_display().to_string();
assert_eq!(temp_dir_display, vroot_restricted_display);
}
#[test]
#[cfg(feature = "virtual-path")]
fn test_virtualroot_unvirtual() {
let temp = tempfile::tempdir().unwrap();
let vroot: VirtualRoot = VirtualRoot::try_new(temp.path()).unwrap();
let temp_dir_ref = vroot.as_unvirtual();
let borrowed_display = temp_dir_ref.strictpath_display().to_string();
assert!(!borrowed_display.is_empty());
}
}