oxedyne/fe2o3/fe2o3_mail/tests/mailqx2_deep.rs
2.3 KiB, 3 runs
created by r2946818238:78318, 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 | //! MAILq-x2: roads to depth that part A may have missed. One case a run (`run_deep2.sh`): an |
| 2 | //! abort ends only its own run. QX_DEPTH sets the levels. |
| 3 | |
| 4 | use oxedyne_fe2o3_core::prelude::*; |
| 5 | use oxedyne_fe2o3_jdat::prelude::*; |
| 6 | use oxedyne_fe2o3_mail::search::{ |
| 7 | Day, |
| 8 | Limits, |
| 9 | Mode, |
| 10 | Query, |
| 11 | Term, |
| 12 | }; |
| 13 | |
| 14 | const TODAY: Day = Day { year: 2026, month: 3, day: 4 }; |
| 15 | const LIM: Limits = Limits { search_regex_max_len: 200, search_max_depth: 32, search_max_terms: 64, |
| 16 | snippet_chars: 40, snippets_per_part: 2, ..Limits::DEFAULT }; |
| 17 | |
| 18 | fn depth() -> usize { std::env::var("QX_DEPTH").ok().and_then(|s| s.parse().ok()).unwrap_or(1000) } |
| 19 | |
| 20 | fn deep() -> Query { |
| 21 | let mut t = Term::Text { scope: None, mode: Mode::Word, text: "a".into() }; |
| 22 | for i in 0..depth() { t = if i % 2 == 0 { Term::Not(Box::new(t)) } else { Term::Any(vec![t]) }; } |
| 23 | Query { terms: t, ..Query::default() } |
| 24 | } |
| 25 | |
| 26 | fn show(what: &str, r: Outcome<Query>) { |
| 27 | eprintln!("QX2 {} depth {}: {}", what, depth(), match r { Ok(q) => fmt!("ACCEPTED, prints {} bytes", q.to_string().len()), Err(e) => fmt!("refused: {}", e) }); |
| 28 | } |
| 29 | |
| 30 | // A scope before a scope: `from:from:...a`, no '(' '{' or '-'. |
| 31 | #[test] |
| 32 | fn x2_deep_key_chain() { |
| 33 | show("from: chain", Query::parse(&("from:".repeat(depth()) + "a"), &LIM)); |
| 34 | } |
| 35 | |
| 36 | #[test] |
| 37 | fn x2_deep_key_chain_mixed() { |
| 38 | show("subject:to: chain", Query::parse(&("subject:to:".repeat(depth() / 2) + "a"), &LIM)); |
| 39 | } |
| 40 | |
| 41 | #[test] |
| 42 | fn x2_deep_clone() { |
| 43 | let q = deep(); |
| 44 | let c = q.clone(); |
| 45 | eprintln!("QX2 clone depth {}: survived {}", depth(), c.terms != Term::default()); |
| 46 | } |
| 47 | |
| 48 | #[test] |
| 49 | fn x2_deep_eq() { |
| 50 | let (a, b) = (deep(), deep()); |
| 51 | eprintln!("QX2 eq depth {}: survived, equal {}", depth(), a == b); |
| 52 | } |
| 53 | |
| 54 | #[test] |
| 55 | fn x2_deep_debug() { |
| 56 | let s = fmt!("{:?}", deep()); |
| 57 | eprintln!("QX2 debug depth {}: survived, {} bytes", depth(), s.len()); |
| 58 | } |
| 59 | |
| 60 | // The JDAT road: the text form of a deep Dat, and a query string inside a Dat. |
| 61 | #[test] |
| 62 | fn x2_deep_jdat_text() { |
| 63 | let n = depth(); |
| 64 | let s = "[".repeat(n) + &"]".repeat(n); |
| 65 | let r = Dat::decode_string(s); |
| 66 | eprintln!("QX2 jdat decode [..] depth {}: {}", n, match &r { Ok(_) => "decoded".to_string(), Err(e) => fmt!("refused: {}", e) }); |
| 67 | if let Ok(d) = r { show("from_dat(list)", Query::from_dat(d, &LIM)); } |
| 68 | show("from_dat(str parens)", Query::from_dat(Dat::Str("(".repeat(n) + "a" + &")".repeat(n)), &LIM)); |
| 69 | } |