use bndpresbufch::{Builder, Error}; #[test] fn close_tx_empty() { let (tx, rx) = Builder::new().max_size(1).build(); drop(tx); assert_eq!(rx.pop(), None); } #[test] fn close_tx_empty_try() { let (tx, rx) = Builder::new().max_size(1).build(); drop(tx); assert_eq!(rx.try_pop(), Err(Error::Closed)); } #[test] fn close_tx_nonempty() { let (tx, rx) = Builder::new().max_size(1).build(); tx.try_push(vec![42]).unwrap(); drop(tx); assert_eq!(rx.pop(), Some(vec![42])); assert_eq!(rx.pop(), None); } #[test] fn close_tx_nonempty_try() { let (tx, rx) = Builder::new().max_size(1).build(); tx.try_push(vec![42]).unwrap(); drop(tx); assert_eq!(rx.try_pop(), Ok(Some(vec![42]))); assert_eq!(rx.try_pop(), Err(Error::Closed)); } #[test] fn close_rx_try() { let (tx, rx) = Builder::new().max_size(1).build(); drop(rx); assert_eq!(tx.try_push(vec![42]), Err(Error::Closed)); } #[test] fn close_rx_force() { let (tx, rx) = Builder::new().max_size(1).build(); drop(rx); assert_eq!(tx.force_push(vec![42]), Err(Error::Closed)); } #[tokio::test] async fn close_tx_empty_async() { let (tx, rx) = Builder::new().max_size(1).build(); drop(tx); assert_eq!(rx.apop().await, Err(Error::Closed)); } #[tokio::test] async fn close_tx_async() { let (tx, rx) = Builder::new().max_size(1).build(); tx.try_push(vec![42]).unwrap(); drop(tx); assert_eq!(rx.apop().await, Ok(vec![42])); assert_eq!(rx.apop().await, Err(Error::Closed)); } // vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :