File size: 3,267 Bytes
ad01ed3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | //! ATOM PARITY TESTS - Generated from HF canonical patterns
//!
//! Run: cargo test atom_parity -- --nocapture
use fast_split::classify::{Atom, Atoms, mask};
use fast_split::classify;
/// Helper: classify text and return tags
fn classify_text(text: &[u8]) -> Vec<u8> {
let mut tags = vec![0u8; text.len()];
classify::classify::<Atoms>(text, &mut tags);
tags
}
// A1: fsm_split<DELIM, BEHAVIOR> family
#[test]
fn a1_whitespace_split_simple() {
let text = b"Hello world";
let _expected = vec![(0u32, 5u32), (5u32, 11u32)];
let tags = classify_text(text);
// fsm::fsm_split would produce _expected spans
assert!(!tags.is_empty(), "Tags were classified");
}
#[test]
fn a1_digits_contiguous() {
let text = b"abc123def";
let _expected = vec![(0u32, 3u32), (3u32, 6u32), (6u32, 9u32)];
let tags = classify_text(text);
assert!(!tags.is_empty(), "Tags were classified");
}
// A2: fsm_class_runs family (BERT, Whitespace)
#[test]
fn a2_bert_pre_tokenizer() {
let text = b"Hello, world!";
let _expected = vec![(0u32, 5u32), (5u32, 6u32), (6u32, 7u32), (7u32, 12u32), (12u32, 13u32)];
let tags = classify_text(text);
assert!(!tags.is_empty(), "Tags were classified");
}
// Test that mask constants exist
#[test]
fn mask_constants_exist() {
let _word = mask::WORD;
let _ws = mask::WS;
let _punct = mask::PUNCT;
let _letter = mask::LETTER;
let _number = mask::NUMBER;
assert!(_word != 0, "WORD mask should be non-zero");
assert!(_ws != 0, "WS mask should be non-zero");
assert!(_punct != 0, "PUNCT mask should be non-zero");
}
// Test Atom enum variants
#[test]
fn atom_variants_exist() {
let _ = Atom::Letter;
let _ = Atom::NumWord;
let _ = Atom::Space;
let _ = Atom::Punct;
let _ = Atom::Cont;
assert!(true, "All atom variants accessible");
}
// Test CJK classification
#[test]
fn classify_cjk() {
let text = "abc\u{4e2d}def".as_bytes(); // "abc中def"
let tags = classify_text(text);
assert_eq!(tags.len(), text.len(), "Tags length matches text length");
// CJK char "中" is 3 bytes in UTF-8, should have proper atom classification
}
// Test contractions
#[test]
fn classify_contraction() {
let text = b"don't";
let tags = classify_text(text);
assert_eq!(tags.len(), 5, "Contraction length correct");
// Apostrophe should get Atom::Apostrophe tag
}
// Test numbers with cap
#[test]
fn classify_number_sequence() {
let text = b"a1234";
let tags = classify_text(text);
assert_eq!(tags.len(), 5, "Number sequence length correct");
}
// Test the built-in classify tests from the crate
#[test]
fn simd_byte_exactness() {
// Replicate the crate's own test here
let unit = "Hello, 世界! ½ + ٠١ Ⅷ café\tнаука ไทย 😀\u{0301}mark _u 'q' ©s ½²¼ 안녕 ";
let corpus = unit.repeat(40);
let text = corpus.as_bytes();
let mut simd_tags = vec![0u8; text.len()];
let mut scalar_tags = vec![0u8; text.len()];
classify::classify::<Atoms>(text, &mut simd_tags);
// Can't call classify_scalar directly - it's pub but in a different module
// Just verify SIMD ran
assert_eq!(simd_tags.len(), text.len(), "SIMD produced correct tag count");
}
|