use std::fmt::Display;
use koek_classify::{Classified, DataClass, DisplayBehavior};
pub const NOT_SECRET_DATA: DataClass = DataClass {
name: "Not Secret",
display_behavior: DisplayBehavior::Clear,
};
pub const SECRET_DATA: DataClass = DataClass {
name: "Secret",
display_behavior: DisplayBehavior::DefaultRedact,
};
#[test]
fn direct_printing_classified_values_works() {
let secret_string = SECRET_DATA.classify("foofoo");
let not_secret_string = NOT_SECRET_DATA.classify("barbar");
println!("The secret value is {}", &secret_string);
println!("The non-secret value is {}", ¬_secret_string);
println!(
"The value inside the secret value is {}",
&secret_string.value
);
println!(
"The value inside the non-secret value is {}",
¬_secret_string.value
);
}
#[test]
fn indirect_printing_classified_values_works() {
let secret_string = SECRET_DATA.classify("foofoo");
let not_secret_string = NOT_SECRET_DATA.classify("barbar");
indirect_print(&secret_string);
indirect_print(¬_secret_string);
}
fn indirect_print(value: &impl Display) {
println!("The value is {}", &value);
}
#[test]
fn counting_classes_works() {
let secret_string = SECRET_DATA.classify("foofoo");
let not_secret_string = NOT_SECRET_DATA.classify("barbar");
count_class(&secret_string);
count_class(¬_secret_string);
}
fn count_class<TValue>(value: &Classified<TValue>) {
let class_name = value.class.name;
println!("The class name is {}", class_name);
}