|
6 | 6 | use std::sync::Arc; |
7 | 7 |
|
8 | 8 | use vortex_buffer::{Buffer, ByteBuffer}; |
9 | | -use vortex_error::{VortexExpect, VortexResult}; |
| 9 | +use vortex_error::{VortexExpect, VortexResult, vortex_ensure}; |
10 | 10 | use vortex_mask::Mask; |
11 | 11 |
|
12 | 12 | use crate::VectorOps; |
@@ -81,6 +81,13 @@ impl<T: BinaryViewType> BinaryViewVector<T> { |
81 | 81 | buffers: Arc<Box<[ByteBuffer]>>, |
82 | 82 | validity: Mask, |
83 | 83 | ) -> VortexResult<Self> { |
| 84 | + vortex_ensure!( |
| 85 | + views.len() == validity.len(), |
| 86 | + "views buffer length {} != validity length {}", |
| 87 | + views.len(), |
| 88 | + validity.len() |
| 89 | + ); |
| 90 | + |
84 | 91 | validate_views( |
85 | 92 | &views, |
86 | 93 | &*buffers, |
@@ -203,9 +210,74 @@ impl<T: BinaryViewType> VectorOps for BinaryViewVector<T> { |
203 | 210 |
|
204 | 211 | #[cfg(test)] |
205 | 212 | mod tests { |
206 | | - use crate::binaryview::StringVectorMut; |
| 213 | + use std::sync::Arc; |
| 214 | + |
| 215 | + use vortex_buffer::{ByteBuffer, buffer}; |
| 216 | + use vortex_mask::Mask; |
| 217 | + |
| 218 | + use crate::binaryview::view::BinaryView; |
| 219 | + use crate::binaryview::{StringVector, StringVectorMut}; |
207 | 220 | use crate::{VectorMutOps, VectorOps}; |
208 | 221 |
|
| 222 | + #[test] |
| 223 | + #[should_panic(expected = "views buffer length 1 != validity length 100")] |
| 224 | + fn test_try_new_mismatch_validity_len() { |
| 225 | + StringVector::try_new( |
| 226 | + buffer![BinaryView::new_inlined(b"inlined")], |
| 227 | + Arc::new(Box::new([])), |
| 228 | + Mask::new_true(100), |
| 229 | + ) |
| 230 | + .unwrap(); |
| 231 | + } |
| 232 | + |
| 233 | + #[test] |
| 234 | + #[should_panic( |
| 235 | + expected = "view at index 0 references invalid buffer: 100 out of bounds for BinaryViewVector with 0 buffers" |
| 236 | + )] |
| 237 | + fn test_try_new_invalid_buffer_offset() { |
| 238 | + StringVector::try_new( |
| 239 | + buffer![BinaryView::make_view(b"bad buffer ptr", 100, 0)], |
| 240 | + Arc::new(Box::new([])), |
| 241 | + Mask::new_true(1), |
| 242 | + ) |
| 243 | + .unwrap(); |
| 244 | + } |
| 245 | + |
| 246 | + #[test] |
| 247 | + #[should_panic(expected = "start offset 4294967295 out of bounds for buffer 0 with size 19")] |
| 248 | + fn test_try_new_invalid_length() { |
| 249 | + StringVector::try_new( |
| 250 | + buffer![BinaryView::make_view(b"bad buffer ptr", 0, u32::MAX)], |
| 251 | + Arc::new(Box::new([ByteBuffer::copy_from(b"a very short buffer")])), |
| 252 | + Mask::new_true(1), |
| 253 | + ) |
| 254 | + .unwrap(); |
| 255 | + } |
| 256 | + |
| 257 | + #[test] |
| 258 | + #[should_panic(expected = "view at index 0: inlined bytes failed utf-8 validation")] |
| 259 | + fn test_try_new_invalid_utf8_inlined() { |
| 260 | + StringVector::try_new( |
| 261 | + buffer![BinaryView::new_inlined(b"\x80")], |
| 262 | + Arc::new(Box::new([])), |
| 263 | + Mask::new_true(1), |
| 264 | + ) |
| 265 | + .unwrap(); |
| 266 | + } |
| 267 | + |
| 268 | + #[test] |
| 269 | + #[should_panic(expected = "view at index 0: outlined bytes failed utf-8 validation")] |
| 270 | + fn test_try_new_invalid_utf8_outlined() { |
| 271 | + // 0xFF is never valid in UTF-8 |
| 272 | + let sequence = b"\xff".repeat(13); |
| 273 | + StringVector::try_new( |
| 274 | + buffer![BinaryView::make_view(&sequence, 0, 0)], |
| 275 | + Arc::new(Box::new([ByteBuffer::copy_from(sequence)])), |
| 276 | + Mask::new_true(1), |
| 277 | + ) |
| 278 | + .unwrap(); |
| 279 | + } |
| 280 | + |
209 | 281 | #[test] |
210 | 282 | fn test_try_into_mut() { |
211 | 283 | let mut shared_vec = StringVectorMut::with_capacity(5); |
|
0 commit comments