invisible_characters/
lib.rs1pub mod invisible_chars;
2pub use invisible_chars::INVISIBLE_CHARS;
3
4pub fn convert_code_to_unicode_char(code: &str) -> char {
5 let hex = u32::from_str_radix(code, 16).unwrap_or_default();
6 char::from_u32(hex).unwrap_or_default()
7}
8
9#[cfg(test)]
10mod test {
11 use crate::INVISIBLE_CHARS;
12 use anyhow::Result;
13
14 #[test]
15 fn code_convert() -> Result<()> {
16 let test_code = "000A";
17 let hex = u32::from_str_radix(test_code, 16)?;
18 let converted = char::from_u32(hex).unwrap_or('a');
19 assert_eq!('\u{000A}', converted);
20 Ok(())
21 }
22
23 #[test]
24 fn first_and_last() -> Result<()> {
25 assert_eq!('\u{0009}', *INVISIBLE_CHARS.first().unwrap());
26 assert_eq!('\u{e0020}', *INVISIBLE_CHARS.last().unwrap());
27 Ok(())
28 }
29
30 #[test]
31 fn flag_or_emoji_fail() -> Result<()> {
32 let has_flag_and_emoji = "hello👋🇦🇴";
33 assert!(!has_flag_and_emoji.contains(INVISIBLE_CHARS));
34 Ok(())
35 }
36}