tree-type 0.4.5

Rust macros for creating type-safe filesystem tree structures
Documentation
//! Test transparent attribute with serde serialization

#![cfg(all(feature = "codegen-v2", feature = "serde"))]

use tempfile::TempDir;
use tree_type::tree_type;

#[test]
fn test_transparent_file_serde() {
    tree_type! {
        Root {
            #[transparent]
            #[default("test content")]
            config("config.toml")
        }
    }

    let temp = TempDir::new().unwrap();
    let root = Root::new(temp.path()).unwrap();

    // Setup creates the file
    root.sync().unwrap();

    let config = root.config();
    assert!(config.exists());

    // Serialize the transparent type
    let json = serde_json::to_string(&config).unwrap();

    // Should serialize as path string, not object with "path" field
    assert!(!json.contains("\"path\""));
    assert!(json.contains("config.toml"));
}

#[test]
fn test_transparent_directory_serde() {
    tree_type! {
        Root {
            #[transparent]
            cache/
        }
    }

    let temp = TempDir::new().unwrap();
    let root = Root::new(temp.path()).unwrap();

    // Setup creates the directory
    root.sync().unwrap();

    let cache = root.cache();
    assert!(cache.exists());

    // Serialize the transparent type
    let json = serde_json::to_string(&cache).unwrap();

    // Should serialize as path string, not object with "path" field
    assert!(!json.contains("\"path\""));
    assert!(json.contains("cache"));
}

#[test]
fn test_non_transparent_file_serde() {
    tree_type! {
        Root {
            #[default("test content")]
            data("data.txt")
        }
    }

    let temp = TempDir::new().unwrap();
    let root = Root::new(temp.path()).unwrap();

    root.sync().unwrap();

    let data = root.data();

    // Serialize the non-transparent type
    let json = serde_json::to_string(&data).unwrap();

    // Should serialize as object with "path" field (normal serde behavior)
    assert!(json.contains("\"path\""));
}