add tests for Events iterators

This commit is contained in:
Matthew Nicholson 2019-03-31 10:14:25 -04:00
parent 6f1021b4a3
commit 2c500dc3f4
1 changed files with 49 additions and 0 deletions

View File

@ -161,3 +161,52 @@ declare_events_struct! {
volumechange,
waiting,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_empty_events_iter() {
let events: Events<&str> = Events::default();
let mut iter = events.iter();
assert_eq!(iter.next(), None);
}
#[test]
fn test_events_iter() {
let mut events: Events<&str> = Events::default();
events.abort = Some("abort");
events.waiting = Some("waiting");
let mut iter = events.iter();
assert_eq!(iter.next(), Some(("abort", &"abort")));
assert_eq!(iter.next(), Some(("waiting", &"waiting")));
assert_eq!(iter.next(), None);
}
#[test]
fn test_events_iter_mut() {
let mut events: Events<&str> = Events::default();
events.abort = Some("abort");
events.waiting = Some("waiting");
let mut iter = events.iter_mut();
assert_eq!(iter.next(), Some(("abort", &mut "abort")));
assert_eq!(iter.next(), Some(("waiting", &mut "waiting")));
assert_eq!(iter.next(), None);
}
#[test]
fn test_events_into_iter() {
let mut events: Events<&str> = Events::default();
events.abort = Some("abort");
events.waiting = Some("waiting");
let mut iter = events.into_iter();
assert_eq!(iter.next(), Some(("abort", "abort")));
assert_eq!(iter.next(), Some(("waiting", "waiting")));
assert_eq!(iter.next(), None);
}
}