#![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();
root.sync().unwrap();
let config = root.config();
assert!(config.exists());
let json = serde_json::to_string(&config).unwrap();
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();
root.sync().unwrap();
let cache = root.cache();
assert!(cache.exists());
let json = serde_json::to_string(&cache).unwrap();
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();
let json = serde_json::to_string(&data).unwrap();
assert!(json.contains("\"path\""));
}