use std::path::PathBuf;
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct PatinaFile {
#[serde(default)]
pub tags: Vec<String>,
pub template: PathBuf,
pub target: PathBuf,
#[serde(default)]
pub preserve_permissions: bool,
#[serde(default)]
pub disable_templating: bool,
}
#[cfg(test)]
mod tests {
use std::path::Path;
use super::*;
impl PatinaFile {
pub fn new<P: AsRef<Path>>(template: P, target: P) -> PatinaFile {
let template = template.as_ref().to_path_buf();
let target = target.as_ref().to_path_buf();
PatinaFile {
template,
target,
tags: vec![],
preserve_permissions: false,
disable_templating: false,
}
}
pub fn new_with_tags<P: AsRef<Path>>(
template: P,
target: P,
tags: Vec<&str>,
) -> PatinaFile {
let mut result = PatinaFile::new(template, target);
result.tags = tags.iter().map(|s| s.to_string()).collect();
result
}
}
#[test]
fn test_patina_file_new() {
let patina_file = PatinaFile::new("template.txt", "target.txt");
assert_eq!(PathBuf::from("template.txt"), patina_file.template);
assert_eq!(PathBuf::from("target.txt"), patina_file.target);
assert!(patina_file.tags.is_empty());
}
#[test]
fn test_patina_file_with_tags() {
let patina_file =
PatinaFile::new_with_tags("template.txt", "target.txt", vec!["aaa", "bbb", "ccc"]);
assert_eq!(PathBuf::from("template.txt"), patina_file.template);
assert_eq!(PathBuf::from("target.txt"), patina_file.target);
assert_eq!(patina_file.tags.len(), 3);
assert_eq!(patina_file.tags[0], "aaa");
assert_eq!(patina_file.tags[1], "bbb");
assert_eq!(patina_file.tags[2], "ccc");
}
}