Return empty iterator for empty string
This commit is contained in:
parent
fbe7b9ad75
commit
5abb2bf790
|
@ -62,7 +62,11 @@ impl Segmenter {
|
|||
input: &str,
|
||||
search: &'a mut Search,
|
||||
) -> Result<impl Iterator<Item = &'a str> + ExactSizeIterator, InvalidCharacter> {
|
||||
SegmentState::new(Ascii::new(input)?, self, search).run();
|
||||
let state = SegmentState::new(Ascii::new(input)?, self, search);
|
||||
if !input.is_empty() {
|
||||
state.run();
|
||||
}
|
||||
|
||||
Ok(search.result.iter().map(|v| v.as_str()))
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ use crate::{Search, Segmenter};
|
|||
/// Run a segmenter against the built-in test cases
|
||||
pub fn run(segmenter: &Segmenter) {
|
||||
let mut search = Search::default();
|
||||
assert_eq!(segmenter.segment("", &mut search).unwrap().len(), 0);
|
||||
|
||||
let mut success = true;
|
||||
for test in TEST_CASES.iter().copied() {
|
||||
success &= assert_segments(test, &mut search, segmenter);
|
||||
|
|
Loading…
Reference in New Issue