From 002a0efa611225ef3b9f2f8f7c2001cac161f1e6 Mon Sep 17 00:00:00 2001 From: Jorge Leitao Date: Tue, 19 Oct 2021 21:33:49 +0200 Subject: [PATCH] Added more tests. (#543) --- tests/it/array/utf8/mod.rs | 44 ++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/tests/it/array/utf8/mod.rs b/tests/it/array/utf8/mod.rs index a81961dc817..d95df91a776 100644 --- a/tests/it/array/utf8/mod.rs +++ b/tests/it/array/utf8/mod.rs @@ -116,6 +116,14 @@ fn not_utf8() { Utf8Array::::from_data(DataType::Utf8, offsets, values, None); } +#[test] +#[should_panic] +fn not_utf8_individually() { + let offsets = Buffer::from(&[0, 1, 2]); + let values = Buffer::from([207, 128]); // each is invalid utf8, but together is valid + Utf8Array::::from_data(DataType::Utf8, offsets, values, None); +} + #[test] #[should_panic] fn wrong_offsets() { @@ -134,37 +142,35 @@ fn wrong_data_type() { #[test] #[should_panic] -fn value_with_wrong_offsets_panics() { - let offsets = Buffer::from(&[0, 10, 11, 4]); +fn out_of_bounds_offsets_panics() { + // the 10 is out of bounds + let offsets = Buffer::from(&[0, 10, 11]); let values = Buffer::from(b"abbb"); - // the 10-11 is not checked - let array = Utf8Array::::from_data(DataType::Utf8, offsets, values, None); - - // but access is still checked (and panics) - // without checks, this would result in reading beyond bounds - array.value(0); + let _ = Utf8Array::::from_data(DataType::Utf8, offsets, values, None); } #[test] #[should_panic] -fn index_out_of_bounds_panics() { - let offsets = Buffer::from(&[0, 1, 2, 4]); +fn decreasing_offset_and_ascii_panics() { + let offsets = Buffer::from(&[0, 2, 1]); let values = Buffer::from(b"abbb"); - let array = Utf8Array::::from_data(DataType::Utf8, offsets, values, None); + let _ = Utf8Array::::from_data(DataType::Utf8, offsets, values, None); +} - array.value(3); +#[test] +#[should_panic] +fn decreasing_offset_and_utf8_panics() { + let offsets = Buffer::from(&[0, 2, 4, 2]); // not increasing + let values = Buffer::from([207, 128, 207, 128, 207, 128]); // valid utf8 + let _ = Utf8Array::::from_data(DataType::Utf8, offsets, values, None); } #[test] #[should_panic] -fn value_unchecked_with_wrong_offsets_panics() { - let offsets = Buffer::from(&[0, 10, 11, 4]); +fn index_out_of_bounds_panics() { + let offsets = Buffer::from(&[0, 1, 2, 4]); let values = Buffer::from(b"abbb"); - // the 10-11 is not checked let array = Utf8Array::::from_data(DataType::Utf8, offsets, values, None); - // but access is still checked (and panics) - // without checks, this would result in reading beyond bounds, - // even if index `0` is in bounds - unsafe { array.value_unchecked(0) }; + array.value(3); }