From 23ff24bdf3b6067aa38f2ffb61112c424c1d0a49 Mon Sep 17 00:00:00 2001 From: xffxff <1247714429@qq.com> Date: Thu, 24 Aug 2023 09:46:01 +0800 Subject: [PATCH] add a test to check if the regex wildcard .* matches any character --- src/results/aggregator.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/results/aggregator.rs b/src/results/aggregator.rs index c2a2cdb..9b93f18 100644 --- a/src/results/aggregator.rs +++ b/src/results/aggregator.rs @@ -258,6 +258,45 @@ mod tests { Ok(()) } + #[test] + fn test_filter_with_lists_wildcard() -> Result<(), Box> { + let mut map_to_be_filtered = HashMap::new(); + map_to_be_filtered.insert( + "https://www.example.com".to_string(), + SearchResult { + title: "Example Domain".to_string(), + url: "https://www.example.com".to_string(), + description: "This domain is for use in illustrative examples in documents.".to_string(), + engine: vec!["Google".to_string(), "Bing".to_string()], + }, + ); + map_to_be_filtered.insert( + "https://www.rust-lang.org/".to_string(), + SearchResult { + title: "Rust Programming Language".to_string(), + url: "https://www.rust-lang.org/".to_string(), + description: "A systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety.".to_string(), + engine: vec!["Google".to_string(), "DuckDuckGo".to_string()], + }, + ); + + // Create a temporary file with a regex pattern containing a wildcard + let mut file = NamedTempFile::new()?; + writeln!(file, "ex.*le")?; + file.flush()?; + + let mut resultant_map = HashMap::new(); + + filter_with_lists(&mut map_to_be_filtered, &mut resultant_map, file.path().to_str().unwrap())?; + + assert_eq!(resultant_map.len(), 1); + assert!(resultant_map.contains_key("https://www.example.com")); + assert_eq!(map_to_be_filtered.len(), 1); + assert!(map_to_be_filtered.contains_key("https://www.rust-lang.org/")); + + Ok(()) + } + #[test] fn test_filter_with_lists_file_not_found() { let mut map_to_be_filtered = HashMap::new();