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 (#1103)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao authored Jun 26, 2022
1 parent 8605f45 commit 406eb3f
Showing 1 changed file with 62 additions and 9 deletions.
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())
}

0 comments on commit 406eb3f

Please sign in to comment.