tokio/tokio-io/tests/read_until.rs
2019-08-20 20:07:16 -07:00

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, []);
}