Skip to content

Commit a074a57

Browse files
committed
test(io): test bufread for AsyncStream
1 parent 5eec94c commit a074a57

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

compio-io/tests/compat.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::io::Cursor;
22

33
use compio_io::compat::AsyncStream;
4-
use futures_util::{AsyncReadExt, AsyncWriteExt};
4+
use futures_util::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt};
55

66
#[tokio::test]
77
async fn async_compat_read() {
@@ -20,6 +20,22 @@ async fn async_compat_read() {
2020
assert_eq!(&buf[..7], [1, 9, 1, 9, 8, 1, 0]);
2121
}
2222

23+
#[tokio::test]
24+
async fn async_compat_bufread() {
25+
let src = &[1u8, 1, 4, 5, 1, 4, 1, 9, 1, 9, 8, 1, 0][..];
26+
let mut stream = AsyncStream::new(src);
27+
28+
let slice = stream.fill_buf().await.unwrap();
29+
assert_eq!(slice, [1, 1, 4, 5, 1, 4, 1, 9, 1, 9, 8, 1, 0]);
30+
stream.consume_unpin(6);
31+
32+
let mut buf = [0; 7];
33+
let len = stream.read(&mut buf).await.unwrap();
34+
35+
assert_eq!(len, 7);
36+
assert_eq!(buf, [1, 9, 1, 9, 8, 1, 0]);
37+
}
38+
2339
#[tokio::test]
2440
async fn async_compat_write() {
2541
let dst = Cursor::new([0u8; 10]);

0 commit comments

Comments
 (0)