tustvold commented on code in PR #6790:
URL: https://github.com/apache/arrow-rs/pull/6790#discussion_r1863801829


##########
arrow-buffer/src/buffer/immutable.rs:
##########
@@ -576,30 +591,30 @@ mod tests {
 
     #[test]
     fn test_shrink_to_fit() {
-        let original = Buffer::from(&[1, 2, 3, 4, 5, 6, 7]);
-        assert_eq!(original.len(), 7);
+        let original = Buffer::from(&[0, 1, 2, 3, 4, 5, 6, 7]);
+        assert_eq!(original.as_slice(), &[0, 1, 2, 3, 4, 5, 6, 7]);
         assert_eq!(original.capacity(), 64);
 
-        let slice = original.slice(3);
+        let slice = original.slice_with_length(2, 3);
         drop(original); // Make sure the buffer isn't shared (or shrink_to_fit 
won't work)
-        assert_eq!(slice.len(), 4);
+        assert_eq!(slice.as_slice(), &[2, 3, 4]);
         assert_eq!(slice.capacity(), 64);
 
         let mut shrunk = slice;
         shrunk.shrink_to_fit();
-        assert_eq!(shrunk.len(), 4);
-        assert_eq!(shrunk.capacity(), 4);
+        assert_eq!(shrunk.as_slice(), &[2, 3, 4]);
+        assert_eq!(shrunk.capacity(), 5); // shrink_to_fit is allowed to keep 
the elements before the offset
 
         // Test that we can handle empty slices:
-        let empty_slice = shrunk.slice(4);
+        let empty_slice = shrunk.slice_with_length(1, 0);
         drop(shrunk); // Make sure the buffer isn't shared (or shrink_to_fit 
won't work)
-        assert_eq!(empty_slice.len(), 0);
-        assert_eq!(empty_slice.capacity(), 4);
+        assert_eq!(empty_slice.as_slice(), &[]);
+        assert_eq!(empty_slice.capacity(), 5);
 
         let mut shrunk_empty = empty_slice;
         shrunk_empty.shrink_to_fit();
-        assert_eq!(shrunk_empty.len(), 0);
-        assert_eq!(shrunk_empty.capacity(), 1); // `Buffer` and `Bytes` 
doesn't support 0-capacity, so we shrink to 1
+        assert_eq!(shrunk_empty.as_slice(), &[]);
+        assert_eq!(shrunk_empty.capacity(), 1); // NOTE: `Buffer` and `Bytes` 
doesn't support 0-capacity

Review Comment:
   Added in https://github.com/apache/arrow-rs/pull/6817



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to