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

Commit

Permalink
Added more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Oct 19, 2021
1 parent bd8f02b commit 31f6d1c
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 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,15 +142,27 @@ fn wrong_data_type() {

#[test]
#[should_panic]
fn value_with_wrong_offsets_panics() {
let offsets = Buffer::from(&[0, 10, 11, 4]);
fn value_with_out_of_bounds_offsets_panics() {
// the 10-11 is out of bounds
let offsets = Buffer::from(&[0, 10, 4]);
let values = Buffer::from(b"abbb");
// the 10-11 is not checked
let array = Utf8Array::<i32>::from_data(DataType::Utf8, offsets, values, None);
let _ = 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);
#[test]
#[should_panic]
fn value_with_wrong_decreasing_offset_panics() {
let offsets = Buffer::from(&[0, 2, 1]);
let values = Buffer::from(b"abbb");
let _ = Utf8Array::<i32>::from_data(DataType::Utf8, offsets, values, None);
}

#[test]
#[should_panic]
fn value_with_wrong_decreasing_offset_and_utf8_panics() {
let offsets = Buffer::from(&[0, 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]
Expand Down

0 comments on commit 31f6d1c

Please sign in to comment.