Skip to content

Commit

Permalink
Test utf8_validation checks char boundaries (#2068)
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold authored Jul 14, 2022
1 parent 11445ee commit 9116297
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions arrow/src/array/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2133,6 +2133,38 @@ mod tests {
check_utf8_validation::<i64>(DataType::LargeUtf8);
}

/// Tests that offsets are at valid codepoint boundaries
fn check_utf8_char_boundary<T: ArrowNativeType>(data_type: DataType) {
let data_buffer = Buffer::from("🙀".as_bytes());
let offsets: Vec<T> = [0, 1, data_buffer.len()]
.iter()
.map(|&v| T::from_usize(v).unwrap())
.collect();

let offsets_buffer = Buffer::from_slice_ref(&offsets);
ArrayData::try_new(
data_type,
2,
None,
0,
vec![offsets_buffer, data_buffer],
vec![],
)
.unwrap();
}

#[test]
#[should_panic(expected = "incomplete utf-8 byte sequence from index 0")]
fn test_validate_utf8_char_boundary() {
check_utf8_char_boundary::<i32>(DataType::Utf8);
}

#[test]
#[should_panic(expected = "incomplete utf-8 byte sequence from index 0")]
fn test_validate_large_utf8_char_boundary() {
check_utf8_char_boundary::<i64>(DataType::LargeUtf8);
}

/// Test that the array of type `data_type` that has invalid indexes (out of bounds)
fn check_index_out_of_bounds_validation<T: ArrowNativeType>(data_type: DataType) {
let data_buffer = Buffer::from_slice_ref(&[b'a', b'b', b'c', b'd']);
Expand Down

0 comments on commit 9116297

Please sign in to comment.