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

Function test_io_read

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

Source from the content-addressed store, hash-verified

507
508 #[crate::test]
509 fn test_io_read() {
510 let s = SegmentedBytes::from(vec![0, 1, 2, 3, 4, 5, 6, 7]);
511 let mut reader = s.reader();
512
513 assert_eq!(reader.len(), 8);
514 assert_eq!(reader.position(), 0);
515
516 // Read a small amount.
517 let mut buf = [0; 4];
518 let bytes_read = reader.read(&mut buf).unwrap();
519 assert_eq!(bytes_read, 4);
520 assert_eq!(buf, [0, 1, 2, 3]);
521
522 // We should still report our original length.
523 assert_eq!(reader.len(), 8);
524 // But our position has moved.
525 assert_eq!(reader.position(), 4);
526
527 // We can seek forwards and read bytes.
528 reader.seek(SeekFrom::Current(1)).unwrap();
529 let bytes_read = reader.read(&mut buf).unwrap();
530 assert_eq!(bytes_read, 3);
531 assert_eq!(buf, [5, 6, 7, 3]);
532
533 assert_eq!(reader.len(), 8);
534 // We've read to the end!
535 assert_eq!(reader.position(), 8);
536
537 // We shouldn't read any bytes
538 let bytes_read = reader.read(&mut buf).unwrap();
539 assert_eq!(bytes_read, 0);
540 // Buffer shouldn't change from what it was last.
541 assert_eq!(buf, [5, 6, 7, 3]);
542
543 // Seek backwards and re-read bytes.
544 reader.seek(SeekFrom::Start(2)).unwrap();
545 let bytes_read = reader.read(&mut buf).unwrap();
546 assert_eq!(bytes_read, 4);
547 assert_eq!(buf, [2, 3, 4, 5]);
548 }
549
550 #[crate::test]
551 fn test_io_read_multi() {

Callers

nothing calls this directly

Calls 4

unwrapMethod · 0.80
seekMethod · 0.80
readerMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected