1 #[test]
cursor_asyncwrite_vec()2 fn cursor_asyncwrite_vec() {
3 use assert_matches::assert_matches;
4 use futures::future::lazy;
5 use futures::io::{AsyncWrite, Cursor};
6 use futures::task::Poll;
7 use std::pin::Pin;
8
9 let mut cursor = Cursor::new(vec![0; 5]);
10 futures::executor::block_on(lazy(|cx| {
11 assert_matches!(Pin::new(&mut cursor).poll_write(cx, &[1, 2]), Poll::Ready(Ok(2)));
12 assert_matches!(Pin::new(&mut cursor).poll_write(cx, &[3, 4]), Poll::Ready(Ok(2)));
13 assert_matches!(Pin::new(&mut cursor).poll_write(cx, &[5, 6]), Poll::Ready(Ok(2)));
14 assert_matches!(Pin::new(&mut cursor).poll_write(cx, &[6, 7]), Poll::Ready(Ok(2)));
15 }));
16 assert_eq!(cursor.into_inner(), [1, 2, 3, 4, 5, 6, 6, 7]);
17 }
18
19 #[test]
cursor_asyncwrite_box()20 fn cursor_asyncwrite_box() {
21 use assert_matches::assert_matches;
22 use futures::future::lazy;
23 use futures::io::{AsyncWrite, Cursor};
24 use futures::task::Poll;
25 use std::pin::Pin;
26
27 let mut cursor = Cursor::new(vec![0; 5].into_boxed_slice());
28 futures::executor::block_on(lazy(|cx| {
29 assert_matches!(Pin::new(&mut cursor).poll_write(cx, &[1, 2]), Poll::Ready(Ok(2)));
30 assert_matches!(Pin::new(&mut cursor).poll_write(cx, &[3, 4]), Poll::Ready(Ok(2)));
31 assert_matches!(Pin::new(&mut cursor).poll_write(cx, &[5, 6]), Poll::Ready(Ok(1)));
32 assert_matches!(Pin::new(&mut cursor).poll_write(cx, &[6, 7]), Poll::Ready(Ok(0)));
33 }));
34 assert_eq!(&*cursor.into_inner(), [1, 2, 3, 4, 5]);
35 }
36