use futures::executor::block_on;
use qanat::oneshot::{channel, TryRecvError};


#[test]
fn sync_oneshot() {
    for _ in 0..100000 {
        let (s, mut r) = channel::<usize>();

        assert_eq!(r.try_recv(), Err(TryRecvError::Empty));
        drop(s);
        assert_eq!(r.try_recv(), Err(TryRecvError::Closed));

        let (s, mut r) = channel();
        assert_eq!(r.try_recv(), Err(TryRecvError::Empty));
        assert_eq!(r.try_recv(), Err(TryRecvError::Empty));
        s.send(1).unwrap();
        assert_eq!(r.try_recv(), Ok(1));
        assert_eq!(r.try_recv(), Err(TryRecvError::Closed));
        assert_eq!(r.try_recv(), Err(TryRecvError::Closed));
    }
}

#[test]
fn async_mpsc() {
    block_on(async {
        for _ in 0..100000 {
            let (s, mut r) = channel();

            assert_eq!(r.try_recv(), Err(TryRecvError::Empty));
            s.send(1).unwrap();
            assert_eq!(r.recv().await, Ok(1));
        }
    });
}
