use bndpresbufch::{Builder, Error}; #[test] fn push_pop() { let (tx, rx) = Builder::new().max_size(1).build(); // Add a node tx.push([1].into()).unwrap(); // Fail to add another node, sinze the max length is exceeded let Err(e) = tx.try_push([2].into()) else { panic!("Unexpectedly not Err() "); }; assert_eq!(e, Error::WontFit(vec![2])); // Take single node off queue assert_eq!(rx.pop(), Some(vec![1])); // Add new node and then take it off again tx.push([3].into()).unwrap(); assert_eq!(rx.pop(), Some(vec![3])); } #[tokio::test] async fn push_pop_async() { let (pusher, puller) = Builder::new().max_size(1).build(); // Add a node pusher.push([1].into()).unwrap(); // Fail to add another node, sinze the max length is exceeded let Err(e) = pusher.try_push([2].into()) else { panic!("Unexpectedly not Err() "); }; assert_eq!(e, Error::WontFit(vec![2])); // Take single node off queue let res = puller.apop().await.unwrap(); assert_eq!(res, vec![1]); // Add new node and then take it off again pusher.push([3].into()).unwrap(); let res = puller.apop().await.unwrap(); assert_eq!(res, vec![3]); } // vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :