1 #![cfg(feature = "full")]
2 use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncSeekExt};
3
4 #[tokio::test]
empty_read_is_cooperative()5 async fn empty_read_is_cooperative() {
6 tokio::select! {
7 biased;
8
9 _ = async {
10 loop {
11 let mut buf = [0u8; 4096];
12 let _ = tokio::io::empty().read(&mut buf).await;
13 }
14 } => {},
15 _ = tokio::task::yield_now() => {}
16 }
17 }
18
19 #[tokio::test]
empty_buf_reads_are_cooperative()20 async fn empty_buf_reads_are_cooperative() {
21 tokio::select! {
22 biased;
23
24 _ = async {
25 loop {
26 let mut buf = String::new();
27 let _ = tokio::io::empty().read_line(&mut buf).await;
28 }
29 } => {},
30 _ = tokio::task::yield_now() => {}
31 }
32 }
33
34 #[tokio::test]
empty_seek()35 async fn empty_seek() {
36 use std::io::SeekFrom;
37
38 let mut empty = tokio::io::empty();
39
40 assert!(matches!(empty.seek(SeekFrom::Start(0)).await, Ok(0)));
41 assert!(matches!(empty.seek(SeekFrom::Start(1)).await, Ok(0)));
42 assert!(matches!(empty.seek(SeekFrom::Start(u64::MAX)).await, Ok(0)));
43
44 assert!(matches!(empty.seek(SeekFrom::End(i64::MIN)).await, Ok(0)));
45 assert!(matches!(empty.seek(SeekFrom::End(-1)).await, Ok(0)));
46 assert!(matches!(empty.seek(SeekFrom::End(0)).await, Ok(0)));
47 assert!(matches!(empty.seek(SeekFrom::End(1)).await, Ok(0)));
48 assert!(matches!(empty.seek(SeekFrom::End(i64::MAX)).await, Ok(0)));
49
50 assert!(matches!(
51 empty.seek(SeekFrom::Current(i64::MIN)).await,
52 Ok(0)
53 ));
54 assert!(matches!(empty.seek(SeekFrom::Current(-1)).await, Ok(0)));
55 assert!(matches!(empty.seek(SeekFrom::Current(0)).await, Ok(0)));
56 assert!(matches!(empty.seek(SeekFrom::Current(1)).await, Ok(0)));
57 assert!(matches!(
58 empty.seek(SeekFrom::Current(i64::MAX)).await,
59 Ok(0)
60 ));
61 }
62