Skip to main content

sil_normalizer/
lib.rs

1#![warn(clippy::pedantic)]
2
3pub mod detect;
4pub mod normalize;
5
6pub use detect::scan_input;
7pub use normalize::normalize_input;
8
9#[cfg(test)]
10mod tests {
11    use super::*;
12
13    #[test]
14    fn test_normalize_removes_zero_width() {
15        let input = "us\u{200B}er";
16        assert_eq!(normalize_input(input), "user");
17    }
18
19    #[test]
20    fn test_scan_detects_zero_width() {
21        let input = "us\u{200B}er";
22        let issues = scan_input(input);
23        assert!(issues.contains(&"ZERO_WIDTH_CHARACTER_DETECTED".to_string()));
24    }
25
26    #[test]
27    fn test_scan_detects_suspicious_unicode() {
28        let input = "раypal";
29        let issues = scan_input(input);
30        assert!(issues.contains(&"SUSPICIOUS_UNICODE_PATTERN".to_string()));
31    }
32
33    #[test]
34    fn test_clean_input_no_issues() {
35        let input = "hello world";
36        let clean = normalize_input(input);
37        let issues = scan_input(input);
38        assert_eq!(clean, "hello world");
39        assert!(issues.is_empty());
40    }
41}