use super::*;
#[test]
fn test_char_kind_word() {
assert_eq!(char_kind('a'), CharKind::Word);
assert_eq!(char_kind('Z'), CharKind::Word);
assert_eq!(char_kind('5'), CharKind::Word);
assert_eq!(char_kind('_'), CharKind::Word);
}
#[test]
fn test_char_kind_punctuation() {
assert_eq!(char_kind('.'), CharKind::Punctuation);
assert_eq!(char_kind(','), CharKind::Punctuation);
assert_eq!(char_kind('!'), CharKind::Punctuation);
assert_eq!(char_kind('@'), CharKind::Punctuation);
assert_eq!(char_kind('('), CharKind::Punctuation);
}
#[test]
fn test_char_kind_whitespace() {
assert_eq!(char_kind(' '), CharKind::Whitespace);
assert_eq!(char_kind('\t'), CharKind::Whitespace);
assert_eq!(char_kind('\n'), CharKind::Whitespace);
}
#[test]
fn test_char_kind_unicode() {
assert_eq!(char_kind('\u{00e9}'), CharKind::Word);
assert_eq!(char_kind('\u{65e5}'), CharKind::Word);
assert_eq!(char_kind('\u{03b1}'), CharKind::Word);
assert_eq!(char_kind('\u{2026}'), CharKind::Punctuation);
}
#[test]
fn test_word_start_small() {
let text: Vec<char> = "hello world".chars().collect();
assert_eq!(word_start(&text, 0, WordType::Small), 0);
assert_eq!(word_start(&text, 3, WordType::Small), 0);
assert_eq!(word_start(&text, 4, WordType::Small), 0);
assert_eq!(word_start(&text, 6, WordType::Small), 6);
assert_eq!(word_start(&text, 10, WordType::Small), 6);
}
#[test]
fn test_word_end_small() {
let text: Vec<char> = "hello world".chars().collect();
assert_eq!(word_end(&text, 0, WordType::Small), 4);
assert_eq!(word_end(&text, 3, WordType::Small), 4);
assert_eq!(word_end(&text, 6, WordType::Small), 10);
}
#[test]
fn test_word_start_big() {
let text: Vec<char> = "foo.bar baz".chars().collect();
assert_eq!(word_start(&text, 4, WordType::Big), 0);
assert_eq!(word_start(&text, 6, WordType::Big), 0);
}
#[test]
fn test_word_end_big() {
let text: Vec<char> = "foo.bar baz".chars().collect();
assert_eq!(word_end(&text, 0, WordType::Big), 6);
assert_eq!(word_end(&text, 4, WordType::Big), 6);
}
#[test]
fn test_word_bounds() {
let text: Vec<char> = "hello world".chars().collect();
let (start, end) = word_bounds(&text, 2, WordType::Small);
assert_eq!(start, 0);
assert_eq!(end, 4);
}
#[test]
fn test_word_bounds_empty_slice() {
let empty: Vec<char> = vec![];
let (start, end) = word_bounds(&empty, 0, WordType::Small);
assert_eq!(start, 0);
assert_eq!(end, 0);
}
#[test]
fn test_word_start_at_boundary() {
let text: Vec<char> = "hello".chars().collect();
assert_eq!(word_start(&text, 0, WordType::Small), 0);
}
#[test]
fn test_word_end_at_boundary() {
let text: Vec<char> = "hello".chars().collect();
assert_eq!(word_end(&text, 4, WordType::Small), 4);
}
#[test]
fn test_word_small_with_punctuation() {
let text: Vec<char> = "foo.bar".chars().collect();
assert_eq!(word_end(&text, 0, WordType::Small), 2); assert_eq!(word_start(&text, 3, WordType::Small), 3); assert_eq!(word_end(&text, 3, WordType::Small), 3); assert_eq!(word_start(&text, 4, WordType::Small), 4); }
#[test]
fn test_next_word_start() {
let text: Vec<char> = "hello world test".chars().collect();
assert_eq!(next_word_start(&text, 0, WordType::Small), 6); assert_eq!(next_word_start(&text, 6, WordType::Small), 12); }
#[test]
fn test_next_word_end() {
let text: Vec<char> = "hello world".chars().collect();
assert_eq!(next_word_end(&text, 0, WordType::Small), 4); assert_eq!(next_word_end(&text, 4, WordType::Small), 10); }
#[test]
fn test_word_type_default() {
assert_eq!(WordType::default(), WordType::Small);
}
#[test]
fn test_whitespace_handling() {
let text: Vec<char> = " hello ".chars().collect();
assert_eq!(word_start(&text, 1, WordType::Small), 1);
assert_eq!(word_end(&text, 1, WordType::Small), 1);
}
#[test]
fn test_next_word_start_bigword_from_whitespace() {
let text: Vec<char> = " hello.world".chars().collect();
let result = next_word_start(&text, 0, WordType::Big);
assert_eq!(result, 2); }
#[test]
fn test_next_word_start_bigword_from_nonws() {
let text: Vec<char> = "hello.world foo".chars().collect();
let result = next_word_start(&text, 0, WordType::Big);
assert_eq!(result, 12); }
#[test]
fn test_next_word_end_at_end() {
let text: Vec<char> = "hello".chars().collect();
let result = next_word_end(&text, 4, WordType::Small);
assert_eq!(result, 4);
}
#[test]
fn test_next_word_end_empty() {
let empty: Vec<char> = vec![];
assert_eq!(next_word_end(&empty, 0, WordType::Small), 0);
}
#[test]
fn test_next_word_start_empty() {
let empty: Vec<char> = vec![];
assert_eq!(next_word_start(&empty, 0, WordType::Small), 0);
}
#[test]
fn test_word_start_beyond_length() {
let text: Vec<char> = "hello".chars().collect();
let result = word_start(&text, 100, WordType::Small);
assert_eq!(result, 0); }
#[test]
fn test_word_end_beyond_length() {
let text: Vec<char> = "hello".chars().collect();
let result = word_end(&text, 100, WordType::Small);
assert_eq!(result, 4); }
#[test]
fn test_next_word_end_with_whitespace_gap() {
let text: Vec<char> = "hello world".chars().collect();
let result = next_word_end(&text, 4, WordType::Small);
assert_eq!(result, 12); }
#[test]
fn test_next_word_end_bigword() {
let text: Vec<char> = "hello.world foo".chars().collect();
let result = next_word_end(&text, 0, WordType::Big);
assert_eq!(result, 10); }
#[test]
fn test_next_word_start_at_end() {
let text: Vec<char> = "hello".chars().collect();
let result = next_word_start(&text, 4, WordType::Small);
assert_eq!(result, 5); }
#[test]
fn test_word_bounds_big_with_punctuation() {
let text: Vec<char> = "foo.bar baz".chars().collect();
let (start, end) = word_bounds(&text, 2, WordType::Big);
assert_eq!(start, 0);
assert_eq!(end, 6); }
#[test]
fn test_char_kind_hash() {
use std::collections::HashSet;
let mut set = HashSet::new();
set.insert(CharKind::Word);
set.insert(CharKind::Punctuation);
set.insert(CharKind::Whitespace);
assert_eq!(set.len(), 3);
}
#[test]
fn test_word_type_hash() {
use std::collections::HashSet;
let mut set = HashSet::new();
set.insert(WordType::Small);
set.insert(WordType::Big);
assert_eq!(set.len(), 2);
}