| 649 | |
| 650 | #[crate::test] |
| 651 | fn test_middle_segment_empty() { |
| 652 | let segments = vec![vec![1, 2], vec![], vec![3, 4, 5, 6]]; |
| 653 | let mut s: SegmentedBytes = segments.clone().into_iter().collect(); |
| 654 | |
| 655 | assert_eq!(s.len(), 6); |
| 656 | assert_eq!(s.remaining(), 6); |
| 657 | |
| 658 | // Read and advanced past the first chunk. |
| 659 | let first_chunk = s.chunk(); |
| 660 | assert_eq!(first_chunk, [1, 2]); |
| 661 | s.advance(first_chunk.len()); |
| 662 | |
| 663 | assert_eq!(s.remaining(), 4); |
| 664 | |
| 665 | // We should skip the empty segment and continue to the next. |
| 666 | let second_chunk = s.chunk(); |
| 667 | assert_eq!(second_chunk, [3, 4, 5, 6]); |
| 668 | |
| 669 | // Recreate SegmentedBytes. |
| 670 | let s: SegmentedBytes = segments.into_iter().collect(); |
| 671 | let mut reader = s.reader(); |
| 672 | |
| 673 | // We should be able to read the first chunk. |
| 674 | let mut buf = [0; 4]; |
| 675 | let bytes_read = reader.read(&mut buf).unwrap(); |
| 676 | assert_eq!(bytes_read, 2); |
| 677 | assert_eq!(buf, [1, 2, 0, 0]); |
| 678 | |
| 679 | // And we should be able to read the second chunk without issue. |
| 680 | let bytes_read = reader.read(&mut buf).unwrap(); |
| 681 | assert_eq!(bytes_read, 4); |
| 682 | assert_eq!(buf, [3, 4, 5, 6]); |
| 683 | |
| 684 | // Seek backwards and read again. |
| 685 | reader.seek(SeekFrom::Current(-2)).unwrap(); |
| 686 | let bytes_read = reader.read(&mut buf).unwrap(); |
| 687 | assert_eq!(bytes_read, 2); |
| 688 | assert_eq!(buf, [5, 6, 5, 6]); |
| 689 | } |
| 690 | |
| 691 | #[crate::test] |
| 692 | fn test_last_segment_empty() { |