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

Added more tests #1111

Merged
merged 1 commit into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
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
6 changes: 2 additions & 4 deletions src/array/utf8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,7 @@ impl<O: Offset> Utf8Array<O> {
P: AsRef<str>,
I: TrustedLen<Item = Option<P>>,
{
// soundness: I is `TrustedLen`
unsafe { Self::from_trusted_len_iter_unchecked(iterator) }
MutableUtf8Array::<O>::from_trusted_len_iter(iterator).into()
}

/// Creates a [`Utf8Array`] from an falible iterator of trusted length.
Expand All @@ -512,8 +511,7 @@ impl<O: Offset> Utf8Array<O> {
P: AsRef<str>,
I: TrustedLen<Item = std::result::Result<Option<P>, E>>,
{
// soundness: I: TrustedLen
unsafe { Self::try_from_trusted_len_iter_unchecked(iter) }
MutableUtf8Array::<O>::try_from_trusted_len_iter(iter).map(|x| x.into())
}

/// Alias for `new`
Expand Down
18 changes: 18 additions & 0 deletions tests/it/array/utf8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,21 @@ fn into_mut_4() {
let array = Utf8Array::<i32>::new(DataType::Utf8, offsets, values, validity);
assert!(array.into_mut().is_right());
}

#[test]
fn rev_iter() {
let array = Utf8Array::<i32>::from(&[Some("hello"), Some(" "), None]);

assert_eq!(
array.into_iter().rev().collect::<Vec<_>>(),
vec![None, Some(" "), Some("hello")]
);
}

#[test]
fn iter_nth() {
let array = Utf8Array::<i32>::from(&[Some("hello"), Some(" "), None]);

assert_eq!(array.iter().nth(1), Some(Some(" ")));
assert_eq!(array.iter().nth(10), None);
}
26 changes: 26 additions & 0 deletions tests/it/array/utf8/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,29 @@ fn test_extend_values() {
assert_eq!(array.offsets().as_slice(), &[0, 2, 7, 12, 17]);
assert_eq!(array.validity(), None,);
}

#[test]
fn test_extend() {
let mut array = MutableUtf8Array::<i32>::new();

array.extend([Some("hi"), None, Some("there"), None].into_iter());

let array: Utf8Array<i32> = array.into();

assert_eq!(
array,
Utf8Array::<i32>::from([Some("hi"), None, Some("there"), None])
);
}

#[test]
fn as_arc() {
let mut array = MutableUtf8Array::<i32>::new();

array.extend([Some("hi"), None, Some("there"), None].into_iter());

assert_eq!(
Utf8Array::<i32>::from([Some("hi"), None, Some("there"), None]),
array.as_arc().as_ref()
);
}