Skip to content

Commit e5baa81

Browse files
committed
coverage
Signed-off-by: Robert Kruszewski <github@robertk.io>
1 parent 2c72ebf commit e5baa81

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

vortex-buffer/src/buffer.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ impl<T> From<BufferMut<T>> for Buffer<T> {
763763
#[cfg(test)]
764764
mod test {
765765
use bytes::Buf;
766+
use rstest::rstest;
766767

767768
use crate::Alignment;
768769
use crate::Buffer;
@@ -831,12 +832,35 @@ mod test {
831832
const LEN: usize = 17;
832833
let alignment = Alignment::new(64);
833834

834-
let buf = Buffer::<u32>::zeroed_aligned(LEN, alignment, Some(Alignment::DEFAULT_ALIGNMENT));
835+
let buf = Buffer::<u32>::zeroed_aligned(LEN, alignment);
835836

836837
assert!(buf.is_aligned(alignment));
837838
assert_eq!(buf.as_slice(), &[0; LEN]);
838839
}
839840

841+
#[test]
842+
fn copy_from_over_aligns_to_default() {
843+
let values = [1u32, 2, 3];
844+
let buf = Buffer::<u32>::copy_from(values);
845+
846+
// The buffer reports the scalar type's alignment, ...
847+
assert_eq!(buf.alignment(), Alignment::of::<u32>());
848+
// ... but the underlying allocation is over-aligned to DEFAULT_ALIGNMENT.
849+
assert!(buf.is_aligned(Alignment::DEFAULT_ALIGNMENT));
850+
assert_eq!(buf.as_slice(), &values);
851+
}
852+
853+
#[test]
854+
fn zeroed_over_aligns_to_default() {
855+
const LEN: usize = 17;
856+
857+
let buf = Buffer::<u32>::zeroed(LEN);
858+
859+
assert_eq!(buf.alignment(), Alignment::of::<u32>());
860+
assert!(buf.is_aligned(Alignment::DEFAULT_ALIGNMENT));
861+
assert_eq!(buf.as_slice(), &[0; LEN]);
862+
}
863+
840864
#[test]
841865
fn from_vec() {
842866
let vec = vec![1, 2, 3, 4, 5];
@@ -855,11 +879,7 @@ mod test {
855879

856880
#[test]
857881
fn empty_slice_preserves_alignment() {
858-
let buf = Buffer::<u64>::zeroed_aligned(
859-
8,
860-
Alignment::new(64),
861-
Some(Alignment::DEFAULT_ALIGNMENT),
862-
);
882+
let buf = Buffer::<u64>::zeroed_aligned(8, Alignment::new(64));
863883
let sliced = buf.slice(0..0);
864884
assert!(sliced.is_empty());
865885
assert_eq!(sliced.alignment(), Alignment::new(64));

vortex-buffer/src/buffer_mut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<T> BufferMut<T> {
161161

162162
/// Create a mutable scalar buffer by copying the contents of the slice.
163163
pub fn copy_from(other: impl AsRef<[T]>) -> Self {
164-
Self::copy_from_aligned(other, Alignment::DEFAULT_ALIGNMENT)
164+
Self::copy_from_aligned(other, Alignment::of::<T>())
165165
}
166166

167167
/// Create a mutable scalar buffer with the alignment by copying the contents of the slice.

0 commit comments

Comments
 (0)