| 421 | |
| 422 | #[crate::test] |
| 423 | fn test_empty() { |
| 424 | let s = SegmentedBytes::default(); |
| 425 | |
| 426 | // We should report as empty. |
| 427 | assert!(s.is_empty()); |
| 428 | assert_eq!(s.len(), 0); |
| 429 | |
| 430 | // An iterator of segments should return nothing. |
| 431 | let mut i = s.clone().into_segments(); |
| 432 | assert_eq!(i.next(), None); |
| 433 | |
| 434 | // bytes::Buf shouldn't report anything as remaining. |
| 435 | assert_eq!(s.remaining(), 0); |
| 436 | // We should get back an empty chunk if we try to read anything. |
| 437 | assert!(s.chunk().is_empty()); |
| 438 | |
| 439 | // Turn ourselves into a type that impls io::Read. |
| 440 | let mut reader = s.reader(); |
| 441 | |
| 442 | // We shouldn't panic, but we shouldn't get back any bytes. |
| 443 | let mut buf = Vec::new(); |
| 444 | let bytes_read = reader.read(&mut buf[..]).unwrap(); |
| 445 | assert_eq!(bytes_read, 0); |
| 446 | |
| 447 | // We should be able to seek past the end without panicking. |
| 448 | reader.seek(SeekFrom::Current(20)).unwrap(); |
| 449 | let bytes_read = reader.read(&mut buf[..]).unwrap(); |
| 450 | assert_eq!(bytes_read, 0); |
| 451 | } |
| 452 | |
| 453 | #[crate::test] |
| 454 | fn test_bytes_buf() { |