use eventsys::{EventBackend, SlotType}; #[test] fn test_batch() { let mut system = EventBackend::default(); // Register events system .register_store::>(SlotType::All) .unwrap(); system .register_store::<(i64, u64)>(SlotType::First) .unwrap(); system.register_store::(SlotType::Last).unwrap(); system .register_store::(SlotType::Cmp(|current, next| *next > 2 * current)) .unwrap(); system .register_store::(SlotType::AllFilter(|next| *next >= 50)) .unwrap(); // call all events system .new_event::>(Box::new((1, 2, 3))) .unwrap(); system .new_event::>(Box::new((5, 6, 7))) .unwrap(); // call first events system.new_event::<(i64, u64)>((-1, 1)).unwrap(); system.new_event::<(i64, u64)>((-2, 1)).unwrap(); // call last events system.new_event::(123).unwrap(); system.new_event::(456).unwrap(); // call compare events system.new_event::(2).unwrap(); system.new_event::(5).unwrap(); system.new_event::(9).unwrap(); // call filter all events system.new_event::(51).unwrap(); system.new_event::(29).unwrap(); system.new_event::(999).unwrap(); // collect triggered events let all_events = system .query_blocking::>() .unwrap() .map(|x| *x) .collect::>(); let first_events = system .query_blocking::<(i64, u64)>() .unwrap() .collect::>(); let last_events = system.query_blocking::().unwrap().collect::>(); let cmp_events = system.query_blocking::().unwrap().collect::>(); let filter_events = system.query_blocking::().unwrap().collect::>(); // check all events assert_eq!(&all_events, &[(1, 2, 3), (5, 6, 7)]); // check first event assert_eq!(&first_events, &[(-1, 1)]); // check last event assert_eq!(&last_events, &[456]); // check cmp event assert_eq!(&cmp_events, &[5]); // check filter event assert_eq!(&filter_events, &[51, 999]); }