Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Added more tests for utf8 #543

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions tests/it/array/utf8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ fn not_utf8() {
Utf8Array::<i32>::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::<i32>::from_data(DataType::Utf8, offsets, values, None);
}

#[test]
#[should_panic]
fn wrong_offsets() {
Expand All @@ -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::<i32>::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::<i32>::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::<i32>::from_data(DataType::Utf8, offsets, values, None);
let _ = Utf8Array::<i32>::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::<i32>::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::<i32>::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);
}