use crate::{path::strict_path::StrictPath, PathBoundary};
use std::path::PathBuf;
#[test]
fn test_strict_path_creation() {
let test_path = PathBuf::from("path");
let temp = tempfile::tempdir().unwrap();
let temp_dir: PathBoundary = PathBoundary::try_new(temp.path()).unwrap();
let path = crate::validator::path_history::PathHistory::new(&test_path);
let validated_path: StrictPath = temp_dir
.strict_join(path.virtualize_to_restriction(&temp_dir))
.unwrap();
assert!(validated_path.strictpath_ends_with("path"));
}
#[test]
fn test_strict_path_debug() {
let test_path = PathBuf::from("path");
let temp = tempfile::tempdir().unwrap();
let temp_dir: PathBoundary = PathBoundary::try_new(temp.path()).unwrap();
let stated_path = crate::validator::path_history::PathHistory::new(test_path);
let file_path: StrictPath = temp_dir
.strict_join(stated_path.virtualize_to_restriction(&temp_dir))
.unwrap();
let debug_str = format!("{file_path:?}");
assert!(debug_str.contains("StrictPath"));
}
#[cfg(feature = "virtual-path")]
#[test]
fn test_virtual_path_as_unvirtual_strict_path() {
use crate::validator::virtual_root::VirtualRoot;
let temp = tempfile::tempdir().unwrap();
let vroot = VirtualRoot::try_new(temp.path()).unwrap();
let virtual_path = vroot.virtual_join("test/file.txt").unwrap();
fn accepts_strict_path(jp: &StrictPath) -> String {
jp.strictpath_display().to_string()
}
let strict_ref: &StrictPath = virtual_path.as_unvirtual();
let result1 = accepts_strict_path(strict_ref);
let virtual_path_clone = virtual_path.clone();
let unvirtual = virtual_path_clone.unvirtual();
let result2 = accepts_strict_path(&unvirtual);
assert_eq!(result1, result2);
assert_eq!(
strict_ref.strictpath_display().to_string(),
unvirtual.strictpath_display().to_string()
);
fn uses_simple_signature(path: &StrictPath) -> String {
path.strictpath_display().to_string()
}
let result3 = uses_simple_signature(virtual_path.as_unvirtual()); let result4 = uses_simple_signature(&unvirtual); assert_eq!(result3, result4);
}