use crate::storage::INVISIBLE_CHARS;
#[test]
fn test_invisible_character_detection() {
let zero_width_space = char::from_u32(0x200B).unwrap();
assert!(INVISIBLE_CHARS.contains(&zero_width_space));
let mut test_string = String::new();
for _ in 0..10 {
test_string.push('a');
test_string.push(zero_width_space);
}
let char_count = test_string.chars().count();
let mut invis_chars_found = 0.0;
for char in test_string.chars() {
if INVISIBLE_CHARS
.iter()
.any(|invis_chars| *invis_chars == char)
{
invis_chars_found += 1.0;
}
}
let invis_char_percentage = invis_chars_found / char_count as f64;
assert_eq!(invis_char_percentage, 0.5);
}
#[test]
fn test_no_invisible_characters() {
let test_string = "This is a normal string with no invisible characters.";
let mut invis_chars_found = 0.0;
for char in test_string.chars() {
if INVISIBLE_CHARS
.iter()
.any(|invis_chars| *invis_chars == char)
{
invis_chars_found += 1.0;
}
}
let char_count = test_string.chars().count();
let invis_char_percentage = invis_chars_found / char_count as f64;
let space_count = test_string.chars().filter(|c| *c == ' ').count() as f64;
let expected_percentage = space_count / char_count as f64;
assert_eq!(invis_char_percentage, expected_percentage);
assert!(INVISIBLE_CHARS.contains(&' '));
}
#[test]
fn test_spaces_as_invisible_characters() {
let test_string = "This string has spaces.";
let mut invis_chars_found = 0.0;
for char in test_string.chars() {
if INVISIBLE_CHARS
.iter()
.any(|invis_chars| *invis_chars == char)
{
invis_chars_found += 1.0;
}
}
let space_count = test_string.chars().filter(|c| *c == ' ').count() as f64;
let expected_percentage = space_count / test_string.len() as f64;
let invis_char_percentage = invis_chars_found / test_string.len() as f64;
assert_eq!(invis_char_percentage, expected_percentage);
}