#[cfg(test)]
mod tests {
use super::*;
#[test]
fn event_debouncer() {
let result = Arc::new(Mutex::new(vec![]));
let result_clone = Arc::clone(&result);
let debouncer = EventDebouncer::new(Duration::from_millis(10), move |s: String| {
result_clone.lock().unwrap().push(s);
});
debouncer.put(String::from("Test"));
debouncer.put(String::from("Test"));
thread::sleep(Duration::from_millis(20));
assert_eq!(result.lock().unwrap().as_slice(), [String::from("Test")]);
}
#[test]
fn mixed_event_debouncer() {
let result = Arc::new(Mutex::new(vec![]));
let result_clone = Arc::clone(&result);
let debouncer = MixedEventDebouncer::new(move |s: String| {
result_clone.lock().unwrap().push(s);
});
debouncer.put(String::from("Test"), Duration::from_millis(10));
debouncer.put(String::from("Test"), Duration::from_millis(10));
thread::sleep(Duration::from_millis(20));
assert_eq!(result.lock().unwrap().as_slice(), [String::from("Test")]);
}
}