/// Verifies that the custom translation works as intended. /// Input: A plaintext string and a mapping of chars to symbols (String) /// Output: A transformed plaintext string, translated with the given mapping #[test] fn translate() { let mapping = std::collections::HashMap::from([ ('a', String::from("4")), ('c', String::from("<")), ('e', String::from("€")), ('m', String::from(r#"/\/\"#)), ('p', String::from("|*")), ('s', String::from("ehs")), ('w', String::from("vv")), ('z', String::from("7_")), ]); let text = "sphinx of black quartz, judge my vow"; let translation = leetspeak::translate_custom(text, &mapping, &true); assert_eq!(translation, r#"ehs|*hinx of bl4")), ('p',String::from("|º")), ('q',String::from("0_")), ('r',String::from("Я")), ('s',String::from("§")), ('t',String::from("†")), ('u',String::from("|_|")), ('v',String::from("|/")), ('w',String::from("(n)")), ('x',String::from("×")), ('y',String::from("¥")), ('z',String::from(r#"-\_"#)), ]); let lhs_translation = leetspeak::translate_custom(lhs_text, &mapping, &false); let rhs_translation = leetspeak::translate_custom(rhs_text, &mapping, &false); assert_eq!(lhs_translation, rhs_translation); } /// Case-insensitve custom translations should prioritize mapping a character without transforming it /// before attempting case-transformation. #[test] fn prioritize_sensitive_mapping() { let text = "SaY"; let mapping = std::collections::HashMap::from([ ('S', String::from("$")), ('s', String::from("5")), ('A', String::from(r#"/-\"#)), ('a', String::from("4")), ('Y', String::from("`/")), ('y', String::from("¥")), ]); let translation = leetspeak::translate_custom(text, &mapping, &false); assert_eq!(translation, "$4`/"); }