tree-type 0.4.5

Rust macros for creating type-safe filesystem tree structures
Documentation
#![allow(deprecated)]

use std::path::Path;
use tree_type::GenericDir;
use tree_type::GenericFile;
use tree_type::tree_type;

tree_type! {
    TestRoot {
        config("config.toml") as ConfigFile,
        data/ as DataDir {
            logs/ as LogsDir
        }
    }
}

#[test]
fn test_as_generic_methods() {
    let root = TestRoot::new("/tmp/test").unwrap();
    let config = root.config();
    let data = root.data();

    // Test as_generic() methods
    let _generic_root: GenericDir = root.as_generic();
    let _generic_config: GenericFile = config.as_generic();
    let _generic_data: GenericDir = data.as_generic();
}

#[test]
fn test_asref_path_trait() {
    let root = TestRoot::new("/tmp/test").unwrap();
    let config = root.config();
    let data = root.data();

    // Test AsRef<Path> trait
    let _root_path: &Path = root.as_ref();
    let _config_path: &Path = config.as_ref();
    let _data_path: &Path = data.as_ref();

    // Test with std library functions that require AsRef<Path>
    assert_eq!(root.as_ref(), Path::new("/tmp/test"));
    assert_eq!(config.as_ref(), Path::new("/tmp/test/config.toml"));
    assert_eq!(data.as_ref(), Path::new("/tmp/test/data"));
}

#[test]
fn test_display_trait() {
    let root = TestRoot::new("/tmp/test").unwrap();
    let config = root.config();
    let data = root.data();

    // Test Display trait
    assert_eq!(format!("{}", root), "/tmp/test");
    assert_eq!(format!("{}", config), "/tmp/test/config.toml");
    assert_eq!(format!("{}", data), "/tmp/test/data");
}

#[test]
fn test_generic_types_traits() {
    let generic_dir = GenericDir::new("/tmp/test").unwrap();
    let generic_file = GenericFile::new("/tmp/test/file.txt").unwrap();

    // Test AsRef<Path> trait on generic types
    let _dir_path: &Path = generic_dir.as_ref();
    let _file_path: &Path = generic_file.as_ref();

    // Test Display trait on generic types
    assert_eq!(format!("{}", generic_dir), "/tmp/test");
    assert_eq!(format!("{}", generic_file), "/tmp/test/file.txt");

    // Test as_generic() methods on generic types (should return self)
    let _same_dir = generic_dir.as_generic();
    let _same_file = generic_file.as_generic();
}

#[test]
fn test_external_usage_patterns() {
    let root = TestRoot::new("/tmp/test").unwrap();

    // Test usage with Command::current_dir (requires AsRef<Path>)
    use std::process::Command;
    let mut _cmd = Command::new("echo");
    _cmd.current_dir(&root);

    // Test usage with WalkDir::new (requires AsRef<Path>)
    #[cfg(feature = "walk")]
    {
        use walkdir::WalkDir;
        let _walk = WalkDir::new(root.data());
    }

    // Test string formatting (requires Display)
    let message = format!("Working in directory: {}", root);
    assert_eq!(message, "Working in directory: /tmp/test");
}