use simd_normalizer::{are_confusable, skeleton};
#[test]
fn skeleton_empty() {
assert_eq!(skeleton(""), "");
}
#[test]
fn skeleton_pure_ascii() {
let s = skeleton("hello");
assert!(!s.is_empty());
}
#[test]
fn skeleton_converges_in_two_passes() {
let inputs = [
"hello",
"apple",
"\u{0430}\u{0440}\u{0440}l\u{0435}", "\u{00C0}test", "12345",
"\u{1F600}", "\u{01C4}", ];
for input in &inputs {
let once = skeleton(input);
let twice = skeleton(&once);
let thrice = skeleton(&twice);
assert_eq!(
twice, thrice,
"skeleton did not converge after two passes for {:?}",
input
);
}
}
#[test]
fn latin_cyrillic_a() {
assert!(
are_confusable("a", "\u{0430}"),
"Latin 'a' and Cyrillic 'а' should be confusable"
);
}
#[test]
fn latin_cyrillic_e() {
assert!(
are_confusable("e", "\u{0435}"),
"Latin 'e' and Cyrillic 'е' should be confusable"
);
}
#[test]
fn latin_cyrillic_o() {
assert!(
are_confusable("o", "\u{043E}"),
"Latin 'o' and Cyrillic 'о' should be confusable"
);
}
#[test]
fn latin_cyrillic_p() {
assert!(
are_confusable("p", "\u{0440}"),
"Latin 'p' and Cyrillic 'р' should be confusable"
);
}
#[test]
fn confusable_word_apple() {
let latin = "apple";
let mixed = "\u{0430}\u{0440}\u{0440}l\u{0435}"; assert!(are_confusable(latin, mixed));
}
#[test]
fn not_confusable_different_words() {
assert!(!are_confusable("hello", "world"));
assert!(!are_confusable("cat", "dog"));
}
#[test]
fn identical_strings_confusable() {
assert!(are_confusable("test", "test"));
assert!(are_confusable("", ""));
}
#[test]
fn mixed_script_homoglyph_sentence() {
let real = "paypal";
let fake = "p\u{0430}yp\u{0430}l"; assert!(are_confusable(real, fake));
}
#[test]
fn skeleton_of_combining_marks() {
let s = skeleton("\u{0300}\u{0301}\u{0302}");
assert!(!s.is_empty());
}
#[test]
fn skeleton_supplementary_chars() {
let _ = skeleton("\u{1F600}\u{1F4A9}\u{1F680}");
}
#[test]
fn skeleton_long_string() {
let input = "The quick brown fox jumps over the lazy dog. ".repeat(100);
let s = skeleton(&input);
assert!(!s.is_empty());
}
#[test]
fn bmp_confusable_no_panics() {
let mut buf = String::new();
for cp in (0u32..=0xFFFF).step_by(16) {
buf.clear();
if let Some(c) = char::from_u32(cp) {
buf.push(c);
let _ = skeleton(&buf);
}
}
}