()
| 428 | #[cfg(not(windows))] |
| 429 | #[test] |
| 430 | fn test_spare_capacity() { |
| 431 | use crate::io::read; |
| 432 | use std::io::{Seek, SeekFrom}; |
| 433 | |
| 434 | // We need to obtain input stream with contents that we can compare |
| 435 | // against, so open our own source file. |
| 436 | let mut input = std::fs::File::open("src/buffer.rs").unwrap(); |
| 437 | |
| 438 | let mut buf = Vec::with_capacity(64); |
| 439 | let nread = read(&input, spare_capacity(&mut buf)).unwrap(); |
| 440 | assert_eq!(nread, buf.capacity()); |
| 441 | assert_eq!(nread, buf.len()); |
| 442 | assert_eq!( |
| 443 | &buf[..58], |
| 444 | b"//! Utilities for functions that return data via buffers.\n" |
| 445 | ); |
| 446 | buf.clear(); |
| 447 | input.seek(SeekFrom::End(-1)).unwrap(); |
| 448 | let nread = read(&input, spare_capacity(&mut buf)).unwrap(); |
| 449 | assert_eq!(nread, 1); |
| 450 | assert_eq!(buf.len(), 1); |
| 451 | buf.clear(); |
| 452 | input.seek(SeekFrom::End(0)).unwrap(); |
| 453 | let nread = read(&input, spare_capacity(&mut buf)).unwrap(); |
| 454 | assert_eq!(nread, 0); |
| 455 | assert!(buf.is_empty()); |
| 456 | } |
| 457 | } |
nothing calls this directly
no test coverage detected