diff options
Diffstat (limited to 'third_party/rust/tokio/tests/io_read_until.rs')
-rw-r--r-- | third_party/rust/tokio/tests/io_read_until.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/third_party/rust/tokio/tests/io_read_until.rs b/third_party/rust/tokio/tests/io_read_until.rs new file mode 100644 index 0000000000..4e0e0d10d3 --- /dev/null +++ b/third_party/rust/tokio/tests/io_read_until.rs @@ -0,0 +1,23 @@ +#![warn(rust_2018_idioms)] +#![cfg(feature = "full")] + +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, []); +} |