#![allow(deprecated)]
use tempfile::TempDir;
use tree_type::tree_type;
tree_type! {
ParentTestRoot {
config/ as ConfigDir {
settings("settings.toml") as SettingsFile
}
src/ as SrcDir {
main("main.rs") as MainFile
}
}
}
#[test]
fn test_parent_method_exists() {
let tempdir = TempDir::new().unwrap();
let root = ParentTestRoot::new(tempdir.path()).unwrap();
let parent_result = root.parent();
assert!(parent_result.is_some());
}
#[test]
fn test_file_parent_method() {
let tempdir = TempDir::new().unwrap();
let root = ParentTestRoot::new(tempdir.path()).unwrap();
std::fs::create_dir_all(tempdir.path().join("config")).unwrap();
std::fs::write(tempdir.path().join("config/settings.toml"), "test").unwrap();
let config = root.config();
let settings = config.settings();
let parent = settings.parent();
assert_eq!(parent.as_path(), config.as_path());
}
#[test]
fn test_directory_parent_method() {
let tempdir = TempDir::new().unwrap();
let root = ParentTestRoot::new(tempdir.path()).unwrap();
std::fs::create_dir_all(tempdir.path().join("config")).unwrap();
let config = root.config();
let parent = config.parent();
assert_eq!(parent.as_path(), root.as_path());
}
#[test]
fn test_generic_parent_methods() {
use tree_type::GenericDir;
use tree_type::GenericFile;
let tempdir = TempDir::new().unwrap();
let test_file_path = tempdir.path().join("test.txt");
std::fs::write(&test_file_path, "content").unwrap();
let generic_file = GenericFile::new(&test_file_path).unwrap();
let file_parent = generic_file.parent();
assert_eq!(file_parent.as_path(), tempdir.path());
let generic_dir = GenericDir::new(tempdir.path()).unwrap();
let dir_parent = generic_dir.parent();
assert!(dir_parent.is_some());
}