MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / test_io_read_multi

Function test_io_read_multi

src/ore/src/bytes.rs:551–591  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

549
550 #[crate::test]
551 fn test_io_read_multi() {
552 let segments = vec![vec![0, 1, 2, 3], vec![4, 5, 6, 7, 8, 9], vec![10, 11]];
553 let s: SegmentedBytes<2> = segments.into_iter().collect();
554 let mut reader = s.reader();
555
556 assert_eq!(reader.len(), 12);
557 assert_eq!(reader.position(), 0);
558
559 // Read up to the first segment.
560 let mut buf = [0; 6];
561 let bytes_read = reader.read(&mut buf).unwrap();
562 assert_eq!(bytes_read, 4);
563 assert_eq!(buf, [0, 1, 2, 3, 0, 0]);
564
565 // Read 5 bytes, which should come from the second segment.
566 let bytes_read = reader.read(&mut buf[1..]).unwrap();
567 assert_eq!(bytes_read, 5);
568 assert_eq!(buf, [0, 4, 5, 6, 7, 8]);
569
570 // Seek backwards to the middle of the first segment.
571 reader.seek(SeekFrom::Start(2)).unwrap();
572 let bytes_read = reader.read(&mut buf).unwrap();
573 assert_eq!(bytes_read, 2);
574 assert_eq!(buf, [2, 3, 5, 6, 7, 8]);
575
576 // Seek past the end.
577 reader.seek(SeekFrom::Start(1000)).unwrap();
578 let bytes_read = reader.read(&mut buf).unwrap();
579 assert_eq!(bytes_read, 0);
580
581 assert_eq!(reader.len(), 12);
582 assert_eq!(reader.position(), 1000);
583
584 // Seek back to the middle.
585 reader.seek(SeekFrom::Start(6)).unwrap();
586 // Read the entire bufffer.
587 let mut buf = Vec::new();
588 let bytes_read = reader.read_to_end(&mut buf).unwrap();
589 assert_eq!(bytes_read, 6);
590 assert_eq!(buf, &[6, 7, 8, 9, 10, 11]);
591 }
592
593 #[crate::test]
594 fn test_multi() {

Callers

nothing calls this directly

Calls 6

unwrapMethod · 0.80
seekMethod · 0.80
collectMethod · 0.45
into_iterMethod · 0.45
readerMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected