use std::borrow::Cow;
pub struct ReadOnly;
impl flyleaf::Policy for ReadOnly {
fn protected(&self, _path: &[String]) -> bool {
true
}
fn sealed(&self, _path: &[String]) -> bool {
true
}
fn display_protected<'a>(&self, value: &'a str) -> Cow<'a, str> {
slpc::display_name(value)
}
}
#[cfg(test)]
mod tests {
use super::ReadOnly;
use flyleaf::Policy as _;
#[test]
fn nothing_is_editable() {
for path in [
vec![],
vec!["title".to_owned()],
vec!["governance".to_owned(), "owner".to_owned()],
vec!["slipcase_version".to_owned()],
] {
assert!(ReadOnly.protected(&path), "{path:?} should not be editable");
}
}
#[test]
fn nothing_can_be_added() {
for path in [
vec![],
vec!["governance".to_owned()],
vec!["tags".to_owned()],
] {
assert!(ReadOnly.sealed(&path), "{path:?} should accept nothing new");
}
}
#[test]
fn a_direction_override_is_escaped_and_ordinary_text_is_not() {
let spoof = "report\u{202E}fdp.exe";
let shown = ReadOnly.display_protected(spoof);
assert!(!shown.contains('\u{202E}'), "{shown}");
let plain = "Master services agreement";
assert_eq!(ReadOnly.display_protected(plain), plain);
}
}