2019-08-10 00:07:57 +09:00
|
|
|
#![warn(rust_2018_idioms)]
|
2019-07-15 15:23:42 +09:00
|
|
|
|
2019-08-07 21:57:37 +02:00
|
|
|
use std::io::Cursor;
|
|
|
|
|
use tokio_io::AsyncBufReadExt;
|
2019-07-15 15:23:42 +09:00
|
|
|
use tokio_test::assert_ok;
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn read_line() {
|
|
|
|
|
let mut buf = String::new();
|
2019-08-07 21:57:37 +02:00
|
|
|
let mut rd = Cursor::new(b"hello\nworld\n\n");
|
2019-07-15 15:23:42 +09:00
|
|
|
|
|
|
|
|
let n = assert_ok!(rd.read_line(&mut buf).await);
|
|
|
|
|
assert_eq!(n, 6);
|
|
|
|
|
assert_eq!(buf, "hello\n");
|
|
|
|
|
buf.clear();
|
|
|
|
|
let n = assert_ok!(rd.read_line(&mut buf).await);
|
|
|
|
|
assert_eq!(n, 6);
|
|
|
|
|
assert_eq!(buf, "world\n");
|
|
|
|
|
buf.clear();
|
|
|
|
|
let n = assert_ok!(rd.read_line(&mut buf).await);
|
|
|
|
|
assert_eq!(n, 1);
|
|
|
|
|
assert_eq!(buf, "\n");
|
|
|
|
|
buf.clear();
|
|
|
|
|
let n = assert_ok!(rd.read_line(&mut buf).await);
|
|
|
|
|
assert_eq!(n, 0);
|
|
|
|
|
assert_eq!(buf, "");
|
|
|
|
|
}
|