2019-08-10 00:07:57 +09:00
|
|
|
#![warn(rust_2018_idioms)]
|
2019-07-15 15:21:09 +09:00
|
|
|
|
2019-08-07 21:57:37 +02:00
|
|
|
use tokio_io::AsyncBufReadExt;
|
2019-07-15 15:21:09 +09:00
|
|
|
use tokio_test::assert_ok;
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn read_until() {
|
|
|
|
|
let mut buf = vec![];
|
2019-08-07 21:57:37 +02:00
|
|
|
let mut rd: &[u8] = b"hello world";
|
2019-07-15 15:21:09 +09:00
|
|
|
|
|
|
|
|
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, []);
|
|
|
|
|
}
|