add a test to check if the regex wildcard .* matches any character
Browse files- src/results/aggregator.rs +39 -0
src/results/aggregator.rs
CHANGED
@@ -258,6 +258,45 @@ mod tests {
|
|
258 |
Ok(())
|
259 |
}
|
260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
#[test]
|
262 |
fn test_filter_with_lists_file_not_found() {
|
263 |
let mut map_to_be_filtered = HashMap::new();
|
|
|
258 |
Ok(())
|
259 |
}
|
260 |
|
261 |
+
#[test]
|
262 |
+
fn test_filter_with_lists_wildcard() -> Result<(), Box<dyn std::error::Error>> {
|
263 |
+
let mut map_to_be_filtered = HashMap::new();
|
264 |
+
map_to_be_filtered.insert(
|
265 |
+
"https://www.example.com".to_string(),
|
266 |
+
SearchResult {
|
267 |
+
title: "Example Domain".to_string(),
|
268 |
+
url: "https://www.example.com".to_string(),
|
269 |
+
description: "This domain is for use in illustrative examples in documents.".to_string(),
|
270 |
+
engine: vec!["Google".to_string(), "Bing".to_string()],
|
271 |
+
},
|
272 |
+
);
|
273 |
+
map_to_be_filtered.insert(
|
274 |
+
"https://www.rust-lang.org/".to_string(),
|
275 |
+
SearchResult {
|
276 |
+
title: "Rust Programming Language".to_string(),
|
277 |
+
url: "https://www.rust-lang.org/".to_string(),
|
278 |
+
description: "A systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety.".to_string(),
|
279 |
+
engine: vec!["Google".to_string(), "DuckDuckGo".to_string()],
|
280 |
+
},
|
281 |
+
);
|
282 |
+
|
283 |
+
// Create a temporary file with a regex pattern containing a wildcard
|
284 |
+
let mut file = NamedTempFile::new()?;
|
285 |
+
writeln!(file, "ex.*le")?;
|
286 |
+
file.flush()?;
|
287 |
+
|
288 |
+
let mut resultant_map = HashMap::new();
|
289 |
+
|
290 |
+
filter_with_lists(&mut map_to_be_filtered, &mut resultant_map, file.path().to_str().unwrap())?;
|
291 |
+
|
292 |
+
assert_eq!(resultant_map.len(), 1);
|
293 |
+
assert!(resultant_map.contains_key("https://www.example.com"));
|
294 |
+
assert_eq!(map_to_be_filtered.len(), 1);
|
295 |
+
assert!(map_to_be_filtered.contains_key("https://www.rust-lang.org/"));
|
296 |
+
|
297 |
+
Ok(())
|
298 |
+
}
|
299 |
+
|
300 |
#[test]
|
301 |
fn test_filter_with_lists_file_not_found() {
|
302 |
let mut map_to_be_filtered = HashMap::new();
|