use std::fs;
use tree_type_proc_macro::tree_type;
tree_type! {
TestTree {
test_file,
test_dir/ {
nested_file
}
}
}
#[test]
fn test_file_methods() {
let temp_dir = tempfile::tempdir().unwrap();
let root = temp_dir.path().join("tree_type_test_file");
fs::create_dir_all(&root).unwrap();
let tree = TestTree::new(&root).unwrap();
let file = tree.test_file();
assert!(!file.exists());
file.write("hello world").unwrap();
assert!(file.exists());
let content = file.read_to_string().unwrap();
assert_eq!(content, "hello world");
}
#[test]
fn test_directory_methods() {
let temp_dir = tempfile::tempdir().unwrap();
let root = temp_dir.path().join("tree_type_test_file");
let tree = TestTree::new(&root).unwrap();
let dir = tree.test_dir();
assert!(!dir.exists());
dir.create_all().unwrap();
assert!(dir.exists());
let nested = dir.nested_file();
nested.write("nested content").unwrap();
assert_eq!(nested.read_to_string().unwrap(), "nested content");
}