MCPcopy Create free account
hub / github.com/apache/arrow-rs / test_slice

Function test_slice

arrow-buffer/src/buffer/immutable.rs:676–695  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

674
675 #[test]
676 fn test_slice() {
677 let buf = Buffer::from(&[2, 4, 6, 8, 10]);
678 let buf2 = buf.slice(2);
679
680 assert_eq!([6, 8, 10], buf2.as_slice());
681 assert_eq!(3, buf2.len());
682 assert_eq!(unsafe { buf.as_ptr().offset(2) }, buf2.as_ptr());
683
684 let buf3 = buf2.slice_with_length(1, 2);
685 assert_eq!([8, 10], buf3.as_slice());
686 assert_eq!(2, buf3.len());
687 assert_eq!(unsafe { buf.as_ptr().offset(3) }, buf3.as_ptr());
688
689 let buf4 = buf.slice(5);
690 let empty_slice: [u8; 0] = [];
691 assert_eq!(empty_slice, buf4.as_slice());
692 assert_eq!(0, buf4.len());
693 assert!(buf4.is_empty());
694 assert_eq!(buf2.slice_with_length(2, 1).as_slice(), &[10]);
695 }
696
697 #[test]
698 fn test_shrink_to_fit() {

Callers

nothing calls this directly

Calls 2

slice_with_lengthMethod · 0.80
sliceMethod · 0.45

Tested by

no test coverage detected