Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_mail/tests/mail_search_tree.rs

1.7 KiB, 3 runs

created by r2946818238:78314, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1//! `search`, the tree: an empty group counts against the terms bound, as parsed and as built.
2
3use oxedyne_fe2o3_core::prelude::*;
4use oxedyne_fe2o3_mail::search::{
5 Day,
6 Limits,
7 Matcher,
8 Query,
9 Term,
10};
11
12use std::time::{
13 Duration,
14 Instant,
15};
16
17const TODAY: Day = Day { year: 2026, month: 3, day: 4 };
18const MAX_TERMS: usize = 6;
19const LIM: Limits = Limits { search_regex_max_len: 200, search_max_depth: 4, search_max_terms: MAX_TERMS,
20 snippet_chars: 40, snippets_per_part: 2, ..Limits::DEFAULT };
21
22fn refused<T: std::fmt::Debug>(r: Outcome<T>) {
23 match r {
24 Ok(x) => panic!("accepted past the bound of {}: {:?}", MAX_TERMS, x),
25 Err(e) => assert!(e.to_string().contains("search_max_terms"), "refused in other words: {}", e),
26 }
27}
28
29// An empty group is a condition of its own (all of nothing holds, any of nothing does not), so it
30// is a term: a million of them are refused as quickly as a million words.
31#[test]
32fn tree_empty_groups_counted() {
33 for g in ["()", "{}", "-()"] {
34 assert!(Query::parse(&vec![g; MAX_TERMS].join(" "), &LIM).is_ok(), "{} x {} refused", g, MAX_TERMS);
35 refused(Query::parse(&vec![g; MAX_TERMS + 1].join(" "), &LIM));
36 }
37 let s = "() ".repeat(1_000_000);
38 let at = Instant::now();
39 refused(Query::parse(&s, &LIM));
40 let t = at.elapsed();
41 eprintln!("TREE a million empty groups refused in {:?}", t);
42 assert!(t < Duration::from_millis(300), "refused only after {:?}", t);
43 let built = Term::Any((0..=MAX_TERMS).map(|_| Term::All(Vec::new())).collect());
44 refused(Matcher::new(&Query { terms: built, ..Query::default() }, &LIM, TODAY).map(|_| ()));
45 assert!(Matcher::new(&Query::default(), &LIM, TODAY).is_ok(), "the empty query refused");
46}