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

Added more tests #1103

Merged
merged 1 commit into from
Jun 26, 2022
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
71 changes: 62 additions & 9 deletions tests/it/array/utf8/to_mutable.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,67 @@
use arrow2::array::Utf8Array;
use arrow2::{array::Utf8Array, bitmap::Bitmap, buffer::Buffer, datatypes::DataType};

#[test]
#[allow(clippy::redundant_clone)]
fn array_to_mutable() {
fn not_shared() {
let array = Utf8Array::<i32>::from(&[Some("hello"), Some(" "), None]);
let mutable = array.into_mut().unwrap_right();
assert!(array.into_mut().is_right());
}

#[test]
#[allow(clippy::redundant_clone)]
fn shared_validity() {
let validity = Bitmap::from([true]);
let array = Utf8Array::<i32>::new(
DataType::Utf8,
vec![0, 1].into(),
b"a".to_vec().into(),
Some(validity.clone()),
);
assert!(array.into_mut().is_left())
}

let array: Utf8Array<i32> = mutable.into();
let array2 = array.clone();
let maybe_mut = array2.into_mut();
// the ref count is 2 we should not get a mutable.
assert!(maybe_mut.is_left())
#[test]
#[allow(clippy::redundant_clone)]
fn shared_values() {
let values: Buffer<u8> = b"a".to_vec().into();
let array = Utf8Array::<i32>::new(
DataType::Utf8,
vec![0, 1].into(),
values.clone(),
Some(Bitmap::from([true])),
);
assert!(array.into_mut().is_left())
}

#[test]
#[allow(clippy::redundant_clone)]
fn shared_offsets_values() {
let offsets: Buffer<i32> = vec![0, 1].into();
let values: Buffer<u8> = b"a".to_vec().into();
let array = Utf8Array::<i32>::new(
DataType::Utf8,
offsets.clone(),
values.clone(),
Some(Bitmap::from([true])),
);
assert!(array.into_mut().is_left())
}

#[test]
#[allow(clippy::redundant_clone)]
fn shared_offsets() {
let offsets: Buffer<i32> = vec![0, 1].into();
let array = Utf8Array::<i32>::new(
DataType::Utf8,
offsets.clone(),
b"a".to_vec().into(),
Some(Bitmap::from([true])),
);
assert!(array.into_mut().is_left())
}

#[test]
#[allow(clippy::redundant_clone)]
fn shared_all() {
let array = Utf8Array::<i32>::from(&[Some("hello"), Some(" "), None]);
assert!(array.clone().into_mut().is_left())
}