diff options
author | Lucio Franco <luciofranco14@gmail.com> | 2019-08-02 15:23:44 -0400 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2019-08-02 12:23:44 -0700 |
commit | ff41108834ab8fdf92e5c337b46637ba696d89c7 (patch) | |
tree | b11dd84a9443281b03432a68a016be813f58017a /tokio/tests/io_read_line.rs | |
parent | 6b202722ea78548b941b3aa6e92ff281a7ce42c5 (diff) |
io: move io helpers back into `tokio-io` (#1377)
Utilities are made optional with a feature flag.
Diffstat (limited to 'tokio/tests/io_read_line.rs')
-rw-r--r-- | tokio/tests/io_read_line.rs | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/tokio/tests/io_read_line.rs b/tokio/tests/io_read_line.rs deleted file mode 100644 index 99b3b59e..00000000 --- a/tokio/tests/io_read_line.rs +++ /dev/null @@ -1,60 +0,0 @@ -#![deny(warnings, rust_2018_idioms)] -#![feature(async_await)] - -use tokio::io::{AsyncBufRead, AsyncBufReadExt, AsyncRead}; -use tokio_test::assert_ok; - -use std::io; -use std::pin::Pin; -use std::task::{Context, Poll}; - -#[tokio::test] -async fn read_line() { - struct Rd { - val: &'static [u8], - } - - impl AsyncRead for Rd { - fn poll_read( - self: Pin<&mut Self>, - _: &mut Context<'_>, - _: &mut [u8], - ) -> Poll<io::Result<usize>> { - unimplemented!() - } - } - - impl AsyncBufRead for Rd { - fn poll_fill_buf<'a>( - self: Pin<&'a mut Self>, - _: &mut Context<'_>, - ) -> Poll<io::Result<&'a [u8]>> { - Poll::Ready(Ok(self.val)) - } - - fn consume(mut self: Pin<&mut Self>, amt: usize) { - self.val = &self.val[amt..]; - } - } - - let mut buf = String::new(); - let mut rd = Rd { - val: b"hello\nworld\n\n", - }; - - let n = assert_ok!(rd.read_line(&mut buf).await); - assert_eq!(n, 6); - assert_eq!(buf, "hello\n"); - buf.clear(); - let n = assert_ok!(rd.read_line(&mut buf).await); - assert_eq!(n, 6); - assert_eq!(buf, "world\n"); - buf.clear(); - let n = assert_ok!(rd.read_line(&mut buf).await); - assert_eq!(n, 1); - assert_eq!(buf, "\n"); - buf.clear(); - let n = assert_ok!(rd.read_line(&mut buf).await); - assert_eq!(n, 0); - assert_eq!(buf, ""); -} |