mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-28 12:10:37 +00:00
23 lines
566 B
Rust
23 lines
566 B
Rust
#![warn(rust_2018_idioms)]
|
|
|
|
use tokio_io::AsyncBufReadExt;
|
|
use tokio_test::assert_ok;
|
|
|
|
#[tokio::test]
|
|
async fn read_until() {
|
|
let mut buf = vec![];
|
|
let mut rd: &[u8] = b"hello world";
|
|
|
|
let n = assert_ok!(rd.read_until(b' ', &mut buf).await);
|
|
assert_eq!(n, 6);
|
|
assert_eq!(buf, b"hello ");
|
|
buf.clear();
|
|
let n = assert_ok!(rd.read_until(b' ', &mut buf).await);
|
|
assert_eq!(n, 5);
|
|
assert_eq!(buf, b"world");
|
|
buf.clear();
|
|
let n = assert_ok!(rd.read_until(b' ', &mut buf).await);
|
|
assert_eq!(n, 0);
|
|
assert_eq!(buf, []);
|
|
}
|