Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io: add test for take bug #4443

Merged
merged 2 commits into from Feb 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions tokio/tests/io_take.rs
Expand Up @@ -17,6 +17,21 @@ async fn take() {
assert_eq!(&buf, &b"hell\0\0"[..]);
}

#[tokio::test]
async fn issue_4435() {
let mut buf = [0; 8];
let rd: &[u8] = b"hello world";

let rd = rd.take(4);
tokio::pin!(rd);

let mut read_buf = ReadBuf::new(&mut buf);
read_buf.put_slice(b"AB");

futures::future::poll_fn(|cx| rd.as_mut().poll_read(cx, &mut read_buf)).await.unwrap();
assert_eq!(&buf, &b"ABhell\0\0"[..]);
}

struct BadReader;

impl AsyncRead for BadReader {
Expand Down