use crate::RedactionStrategy;
use std::fmt;
#[derive(Default, Clone)]
pub struct FullRedactor;
impl<T: AsRef<str>> RedactionStrategy<T> for FullRedactor {
fn display(&self, value: &T, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let len = value.as_ref().chars().count().max(6);
for _ in 0..len {
write!(f, "*")?;
}
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::Redacted;
fn full(input: &str) -> String {
Redacted::<_, FullRedactor>::new(input).to_string()
}
#[test]
fn test_full_redaction() {
assert_eq!(full("secret"), "******");
assert_eq!(full("verylongsecret"), "**************");
}
#[test]
fn test_minimum_length() {
assert_eq!(full("abc"), "******");
assert_eq!(full("a"), "******");
assert_eq!(full(""), "******");
}
#[test]
fn test_unicode() {
assert_eq!(full("안녕하세요한글"), "*******");
}
}