diff --git a/application/apps/indexer/processor/src/search/searchers/mod.rs b/application/apps/indexer/processor/src/search/searchers/mod.rs index a1e0fe5c7..f1339e2e9 100644 --- a/application/apps/indexer/processor/src/search/searchers/mod.rs +++ b/application/apps/indexer/processor/src/search/searchers/mod.rs @@ -20,6 +20,8 @@ use uuid::Uuid; pub mod linear; pub mod regular; #[cfg(test)] +pub mod tests_linear; +#[cfg(test)] pub mod tests_regular; #[cfg(test)] pub mod tests_values; diff --git a/application/apps/indexer/processor/src/search/searchers/tests_linear.rs b/application/apps/indexer/processor/src/search/searchers/tests_linear.rs new file mode 100644 index 000000000..8fd2f5fcb --- /dev/null +++ b/application/apps/indexer/processor/src/search/searchers/tests_linear.rs @@ -0,0 +1,66 @@ +use crate::search::{filter::SearchFilter, searchers::linear::LineSearcher}; + +#[cfg(test)] +const SAMPLES: &[&str] = &[ + "[Info](1.3): a", + "[Warn](1.4): b", + "[Info](1.5): c", + "[Err](1.6): d", + "[err](1.6): d", + "[Info](1.7): e", + "[Info](1.8): f", + "[warn](1.4): b", +]; + +#[test] +fn test_linear() -> Result<(), std::io::Error> { + let cases: Vec<(SearchFilter, &[usize])> = vec![ + ( + SearchFilter::plain(r"[Err]") + .regex(false) + .ignore_case(true) + .word(false), + &[3, 4], + ), + ( + SearchFilter::plain(r"[err]") + .regex(false) + .ignore_case(true) + .word(false), + &[3, 4], + ), + ( + SearchFilter::plain(r"[err]") + .regex(false) + .ignore_case(false) + .word(false), + &[4], + ), + ( + SearchFilter::plain(r"\[Warn\]") + .regex(true) + .ignore_case(true) + .word(false), + &[1, 7], + ), + ( + SearchFilter::plain(r"warn") + .regex(true) + .ignore_case(false) + .word(false), + &[7], + ), + ]; + for (filter, matches) in cases.into_iter() { + let searcher = LineSearcher::new(&filter) + .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err.to_string()))?; + for (n, smpl) in SAMPLES.iter().enumerate() { + if searcher.is_match(smpl) { + assert!(matches.contains(&n)); + } else { + assert!(!matches.contains(&n)); + } + } + } + Ok(()) +}