1#![warn(rust_2018_idioms)]
2#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support file operations
3
4use tempfile::NamedTempFile;
5use tokio::fs::File;
6use tokio::io::{AsyncBufReadExt, BufReader};
7use tokio_test::assert_ok;
8
9#[tokio::test]
10async fn fill_buf_file() {
11 let file = NamedTempFile::new().unwrap();
12
13 assert_ok!(std::fs::write(file.path(), b"hello"));
14
15 let file = assert_ok!(File::open(file.path()).await);
16 let mut file = BufReader::new(file);
17
18 let mut contents = Vec::new();
19
20 loop {
21 let consumed = {
22 let buffer = assert_ok!(file.fill_buf().await);
23 if buffer.is_empty() {
24 break;
25 }
26 contents.extend_from_slice(buffer);
27 buffer.len()
28 };
29
30 file.consume(consumed);
31 }
32
33 assert_eq!(contents, b"hello");
34}
35