//! 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 { let mut tags = vec![0u8; text.len()]; classify::classify::(text, &mut tags); tags } // A1: fsm_split 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::(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"); }