use irgx::corpus::{Cancel, Corpus, sieve::Sieve, tree::Search, walk::Walk};
use irgx::{Regex, codex::Codex, needles::Needles, promise::Literals};
fn needs_send<T: Send>() {}
fn needs_sync<T: Sync>() {}
#[test]
fn a_cancel_token_crosses_threads_because_that_is_its_entire_purpose() {
needs_send::<Cancel>();
needs_sync::<Cancel>();
let cancel = Cancel::new().unwrap();
let other = cancel.clone();
std::thread::spawn(move || other.request()).join().unwrap();
}
#[test]
fn a_regex_still_crosses_threads() {
needs_send::<Regex>();
needs_sync::<Regex>();
}
#[test]
fn the_negative_cases() {
let _ = std::mem::size_of::<Search<'static>>();
let _ = std::mem::size_of::<Walk>();
let _ = std::mem::size_of::<Sieve>();
let _ = std::mem::size_of::<Codex>();
let _ = std::mem::size_of::<Needles>();
let _ = std::mem::size_of::<Literals>();
let _ = std::mem::size_of::<Corpus>();
}
#[test]
fn the_documented_sharing_pattern_compiles_and_runs() {
let cancel = Cancel::new().unwrap();
let watcher = cancel.clone();
let stopper = std::thread::spawn(move || {
std::thread::sleep(std::time::Duration::from_millis(5));
watcher.request();
});
let dir = tempfile::tempdir().unwrap();
std::fs::write(dir.path().join("f.txt"), "needle\n").unwrap();
let corpus = Corpus::open(&[dir.path()]).unwrap();
let query = irgx::corpus::tree::Query::new(b"needle").cancel(&cancel);
let _ = corpus.search(&query);
stopper.join().unwrap();
}