summaryrefslogtreecommitdiffstats
path: root/tokio/tests/io_take.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tokio/tests/io_take.rs')
-rw-r--r--tokio/tests/io_take.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/tokio/tests/io_take.rs b/tokio/tests/io_take.rs
new file mode 100644
index 00000000..7b3363e0
--- /dev/null
+++ b/tokio/tests/io_take.rs
@@ -0,0 +1,15 @@
+#![warn(rust_2018_idioms)]
+
+use tokio::io::AsyncReadExt;
+use tokio_test::assert_ok;
+
+#[tokio::test]
+async fn take() {
+ let mut buf = [0; 6];
+ let rd: &[u8] = b"hello world";
+
+ let mut rd = rd.take(4);
+ let n = assert_ok!(rd.read(&mut buf).await);
+ assert_eq!(n, 4);
+ assert_eq!(&buf, &b"hell\0\0"[..]);
+}