mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-28 12:10:37 +00:00
27 lines
683 B
Rust
27 lines
683 B
Rust
#![warn(rust_2018_idioms)]
|
|
#![feature(async_await)]
|
|
|
|
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
|
use tokio_test::io::Builder;
|
|
|
|
#[tokio::test]
|
|
async fn read() {
|
|
let mut mock = Builder::new().read(b"hello ").read(b"world!").build();
|
|
|
|
let mut buf = [0; 256];
|
|
|
|
let n = mock.read(&mut buf).await.expect("read 1");
|
|
assert_eq!(&buf[..n], b"hello ");
|
|
|
|
let n = mock.read(&mut buf).await.expect("read 2");
|
|
assert_eq!(&buf[..n], b"world!");
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn write() {
|
|
let mut mock = Builder::new().write(b"hello ").write(b"world!").build();
|
|
|
|
mock.write_all(b"hello ").await.expect("write 1");
|
|
mock.write_all(b"world!").await.expect("write 2");
|
|
}
|