use bndpresbufch::{Builder, Error}; #[test] fn perfect_force_fit() { // Create a queue that can hold at most 4 bytes of data let (pusher, puller) = Builder::new().max_size(4).build(); // Fill queue up with 4 1-byte nodes for idx in 0..4 { pusher.try_push([idx].into()).unwrap(); } // Force push a single buffer that is 4 bytes in size, which should eject all // the single-byte nodes. pusher.force_push([4, 5, 6, 7].into()).unwrap(); let Some(buf) = puller.pop() else { panic!("Unexpectedly unable to get a buffer from queue"); }; assert_eq!(buf, &[4, 5, 6, 7]); let Ok(None) = puller.try_pop() else { panic!("Queue unexpectedly not empty"); }; } #[test] fn force_too_big() { let (tx, rx) = Builder::new().max_size(2).build(); assert_eq!( tx.force_push(vec![1, 2, 3]), Err(Error::WontFit(vec![1, 2, 3])) ); assert_eq!(rx.try_pop(), Ok(None)); } // vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :