Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
use itertools::Itertools;
struct PanickingCounter {
curr: usize,
max: usize,
}
impl Iterator for PanickingCounter {
type Item = ();
fn next(&mut self) -> Option<Self::Item> {
self.curr += 1;
assert_ne!(
self.curr, self.max,
"Input iterator reached maximum of {} suggesting collection by adaptor",
self.max
);
Some(())
}
}
fn no_collect_test<A, T>(to_adaptor: T)
where
A: Iterator,
T: Fn(PanickingCounter) -> A,
{
let counter = PanickingCounter {
curr: 0,
max: 10_000,
};
let adaptor = to_adaptor(counter);
for _ in adaptor.take(5) {}
}
#[test]
fn permutations_no_collect() {
no_collect_test(|iter| iter.permutations(5))
}
#[test]
fn combinations_no_collect() {
no_collect_test(|iter| iter.combinations(5))
}
#[test]
fn combinations_with_replacement_no_collect() {
no_collect_test(|iter| iter.combinations_with_replacement(5))
}

76
vendor/itertools/tests/flatten_ok.rs vendored Normal file
View File

@@ -0,0 +1,76 @@
use itertools::{assert_equal, Itertools};
use std::{ops::Range, vec::IntoIter};
fn mix_data() -> IntoIter<Result<Range<i32>, bool>> {
vec![Ok(0..2), Err(false), Ok(2..4), Err(true), Ok(4..6)].into_iter()
}
fn ok_data() -> IntoIter<Result<Range<i32>, bool>> {
vec![Ok(0..2), Ok(2..4), Ok(4..6)].into_iter()
}
#[test]
fn flatten_ok_mixed_expected_forward() {
assert_equal(
mix_data().flatten_ok(),
vec![
Ok(0),
Ok(1),
Err(false),
Ok(2),
Ok(3),
Err(true),
Ok(4),
Ok(5),
],
);
}
#[test]
fn flatten_ok_mixed_expected_reverse() {
assert_equal(
mix_data().flatten_ok().rev(),
vec![
Ok(5),
Ok(4),
Err(true),
Ok(3),
Ok(2),
Err(false),
Ok(1),
Ok(0),
],
);
}
#[test]
fn flatten_ok_collect_mixed_forward() {
assert_eq!(
mix_data().flatten_ok().collect::<Result<Vec<_>, _>>(),
Err(false)
);
}
#[test]
fn flatten_ok_collect_mixed_reverse() {
assert_eq!(
mix_data().flatten_ok().rev().collect::<Result<Vec<_>, _>>(),
Err(true)
);
}
#[test]
fn flatten_ok_collect_ok_forward() {
assert_eq!(
ok_data().flatten_ok().collect::<Result<Vec<_>, _>>(),
Ok((0..6).collect())
);
}
#[test]
fn flatten_ok_collect_ok_reverse() {
assert_eq!(
ok_data().flatten_ok().rev().collect::<Result<Vec<_>, _>>(),
Ok((0..6).rev().collect())
);
}

283
vendor/itertools/tests/laziness.rs vendored Normal file
View File

@@ -0,0 +1,283 @@
#![allow(unstable_name_collisions)]
use itertools::Itertools;
#[derive(Debug, Clone)]
#[must_use = "iterators are lazy and do nothing unless consumed"]
struct Panicking;
impl Iterator for Panicking {
type Item = u8;
fn next(&mut self) -> Option<u8> {
panic!("iterator adaptor is not lazy")
}
fn size_hint(&self) -> (usize, Option<usize>) {
(0, Some(0))
}
}
impl ExactSizeIterator for Panicking {}
/// ## Usage example
/// ```compile_fail
/// must_use_tests! {
/// name {
/// Panicking.name(); // Add `let _ =` only if required (encountered error).
/// }
/// // ...
/// }
/// ```
///
/// **TODO:** test missing `must_use` attributes better, maybe with a new lint.
macro_rules! must_use_tests {
($($(#[$attr:meta])* $name:ident $body:block)*) => {
$(
/// `#[deny(unused_must_use)]` should force us to ignore the resulting iterators
/// by adding `let _ = ...;` on every iterator.
/// If it does not, then a `must_use` attribute is missing on the associated struct.
///
/// However, it's only helpful if we don't add `let _ =` before seeing if there is an error or not.
/// And it does not protect us against removed `must_use` attributes.
/// There is no simple way to test this yet.
#[deny(unused_must_use)]
#[test]
$(#[$attr])*
fn $name() $body
)*
};
}
must_use_tests! {
// Itertools trait:
interleave {
let _ = Panicking.interleave(Panicking);
}
interleave_shortest {
let _ = Panicking.interleave_shortest(Panicking);
}
intersperse {
let _ = Panicking.intersperse(0);
}
intersperse_with {
let _ = Panicking.intersperse_with(|| 0);
}
get {
let _ = Panicking.get(1..4);
let _ = Panicking.get(1..=4);
let _ = Panicking.get(1..);
let _ = Panicking.get(..4);
let _ = Panicking.get(..=4);
let _ = Panicking.get(..);
}
zip_longest {
let _ = Panicking.zip_longest(Panicking);
}
zip_eq {
let _ = Panicking.zip_eq(Panicking);
}
batching {
let _ = Panicking.batching(Iterator::next);
}
chunk_by {
// ChunkBy
let _ = Panicking.chunk_by(|x| *x);
// Groups
let _ = Panicking.chunk_by(|x| *x).into_iter();
}
chunks {
// IntoChunks
let _ = Panicking.chunks(1);
let _ = Panicking.chunks(2);
// Chunks
let _ = Panicking.chunks(1).into_iter();
let _ = Panicking.chunks(2).into_iter();
}
tuple_windows {
let _ = Panicking.tuple_windows::<(_,)>();
let _ = Panicking.tuple_windows::<(_, _)>();
let _ = Panicking.tuple_windows::<(_, _, _)>();
}
circular_tuple_windows {
let _ = Panicking.circular_tuple_windows::<(_,)>();
let _ = Panicking.circular_tuple_windows::<(_, _)>();
let _ = Panicking.circular_tuple_windows::<(_, _, _)>();
}
tuples {
let _ = Panicking.tuples::<(_,)>();
let _ = Panicking.tuples::<(_, _)>();
let _ = Panicking.tuples::<(_, _, _)>();
}
tee {
let _ = Panicking.tee();
}
map_into {
let _ = Panicking.map_into::<u16>();
}
map_ok {
let _ = Panicking.map(Ok::<u8, ()>).map_ok(|x| x + 1);
}
filter_ok {
let _ = Panicking.map(Ok::<u8, ()>).filter_ok(|x| x % 2 == 0);
}
filter_map_ok {
let _ = Panicking.map(Ok::<u8, ()>).filter_map_ok(|x| {
if x % 2 == 0 {
Some(x + 1)
} else {
None
}
});
}
flatten_ok {
let _ = Panicking.map(|x| Ok::<_, ()>([x])).flatten_ok();
}
merge {
let _ = Panicking.merge(Panicking);
}
merge_by {
let _ = Panicking.merge_by(Panicking, |_, _| true);
}
merge_join_by {
let _ = Panicking.merge_join_by(Panicking, |_, _| true);
let _ = Panicking.merge_join_by(Panicking, Ord::cmp);
}
#[should_panic]
kmerge {
let _ = Panicking.map(|_| Panicking).kmerge();
}
#[should_panic]
kmerge_by {
let _ = Panicking.map(|_| Panicking).kmerge_by(|_, _| true);
}
cartesian_product {
let _ = Panicking.cartesian_product(Panicking);
}
multi_cartesian_product {
let _ = vec![Panicking, Panicking, Panicking].into_iter().multi_cartesian_product();
}
coalesce {
let _ = Panicking.coalesce(|x, y| if x == y { Ok(x) } else { Err((x, y)) });
}
dedup {
let _ = Panicking.dedup();
}
dedup_by {
let _ = Panicking.dedup_by(|_, _| true);
}
dedup_with_count {
let _ = Panicking.dedup_with_count();
}
dedup_by_with_count {
let _ = Panicking.dedup_by_with_count(|_, _| true);
}
duplicates {
let _ = Panicking.duplicates();
}
duplicates_by {
let _ = Panicking.duplicates_by(|x| *x);
}
unique {
let _ = Panicking.unique();
}
unique_by {
let _ = Panicking.unique_by(|x| *x);
}
peeking_take_while {
let _ = Panicking.peekable().peeking_take_while(|x| x % 2 == 0);
}
take_while_ref {
let _ = Panicking.take_while_ref(|x| x % 2 == 0);
}
take_while_inclusive {
let _ = Panicking.take_while_inclusive(|x| x % 2 == 0);
}
while_some {
let _ = Panicking.map(Some).while_some();
}
tuple_combinations1 {
let _ = Panicking.tuple_combinations::<(_,)>();
}
#[should_panic]
tuple_combinations2 {
let _ = Panicking.tuple_combinations::<(_, _)>();
}
#[should_panic]
tuple_combinations3 {
let _ = Panicking.tuple_combinations::<(_, _, _)>();
}
combinations {
let _ = Panicking.combinations(0);
let _ = Panicking.combinations(1);
let _ = Panicking.combinations(2);
}
combinations_with_replacement {
let _ = Panicking.combinations_with_replacement(0);
let _ = Panicking.combinations_with_replacement(1);
let _ = Panicking.combinations_with_replacement(2);
}
permutations {
let _ = Panicking.permutations(0);
let _ = Panicking.permutations(1);
let _ = Panicking.permutations(2);
}
powerset {
let _ = Panicking.powerset();
}
pad_using {
let _ = Panicking.pad_using(25, |_| 10);
}
with_position {
let _ = Panicking.with_position();
}
positions {
let _ = Panicking.positions(|v| v % 2 == 0);
}
update {
let _ = Panicking.update(|n| *n += 1);
}
multipeek {
let _ = Panicking.multipeek();
}
// Not iterator themselves but still lazy.
into_grouping_map {
let _ = Panicking.map(|x| (x, x + 1)).into_grouping_map();
}
into_grouping_map_by {
let _ = Panicking.into_grouping_map_by(|x| *x);
}
// Macros:
iproduct {
let _ = itertools::iproduct!(Panicking);
let _ = itertools::iproduct!(Panicking, Panicking);
let _ = itertools::iproduct!(Panicking, Panicking, Panicking);
}
izip {
let _ = itertools::izip!(Panicking);
let _ = itertools::izip!(Panicking, Panicking);
let _ = itertools::izip!(Panicking, Panicking, Panicking);
}
chain {
let _ = itertools::chain!(Panicking);
let _ = itertools::chain!(Panicking, Panicking);
let _ = itertools::chain!(Panicking, Panicking, Panicking);
}
// Free functions:
multizip {
let _ = itertools::multizip((Panicking, Panicking));
}
put_back {
let _ = itertools::put_back(Panicking);
let _ = itertools::put_back(Panicking).with_value(15);
}
peek_nth {
let _ = itertools::peek_nth(Panicking);
}
put_back_n {
let _ = itertools::put_back_n(Panicking);
}
rciter {
let _ = itertools::rciter(Panicking);
}
}

View File

@@ -0,0 +1,27 @@
mod alloc {}
mod core {}
mod either {}
mod std {}
#[test]
fn iproduct_hygiene() {
let _ = itertools::iproduct!();
let _ = itertools::iproduct!(0..6);
let _ = itertools::iproduct!(0..6, 0..9);
let _ = itertools::iproduct!(0..6, 0..9, 0..12);
}
#[test]
fn izip_hygiene() {
let _ = itertools::izip!(0..6);
let _ = itertools::izip!(0..6, 0..9);
let _ = itertools::izip!(0..6, 0..9, 0..12);
}
#[test]
fn chain_hygiene() {
let _: ::std::iter::Empty<i32> = itertools::chain!();
let _ = itertools::chain!(0..6);
let _ = itertools::chain!(0..6, 0..9);
let _ = itertools::chain!(0..6, 0..9, 0..12);
}

101
vendor/itertools/tests/merge_join.rs vendored Normal file
View File

@@ -0,0 +1,101 @@
use itertools::free::merge_join_by;
use itertools::EitherOrBoth;
#[test]
fn empty() {
let left: Vec<u32> = vec![];
let right: Vec<u32> = vec![];
let expected_result: Vec<EitherOrBoth<u32>> = vec![];
let actual_result = merge_join_by(left, right, |l, r| l.cmp(r)).collect::<Vec<_>>();
assert_eq!(expected_result, actual_result);
}
#[test]
fn left_only() {
let left: Vec<u32> = vec![1, 2, 3];
let right: Vec<u32> = vec![];
let expected_result: Vec<EitherOrBoth<u32>> = vec![
EitherOrBoth::Left(1),
EitherOrBoth::Left(2),
EitherOrBoth::Left(3),
];
let actual_result = merge_join_by(left, right, |l, r| l.cmp(r)).collect::<Vec<_>>();
assert_eq!(expected_result, actual_result);
}
#[test]
fn right_only() {
let left: Vec<u32> = vec![];
let right: Vec<u32> = vec![1, 2, 3];
let expected_result: Vec<EitherOrBoth<u32>> = vec![
EitherOrBoth::Right(1),
EitherOrBoth::Right(2),
EitherOrBoth::Right(3),
];
let actual_result = merge_join_by(left, right, |l, r| l.cmp(r)).collect::<Vec<_>>();
assert_eq!(expected_result, actual_result);
}
#[test]
fn first_left_then_right() {
let left: Vec<u32> = vec![1, 2, 3];
let right: Vec<u32> = vec![4, 5, 6];
let expected_result: Vec<EitherOrBoth<u32>> = vec![
EitherOrBoth::Left(1),
EitherOrBoth::Left(2),
EitherOrBoth::Left(3),
EitherOrBoth::Right(4),
EitherOrBoth::Right(5),
EitherOrBoth::Right(6),
];
let actual_result = merge_join_by(left, right, |l, r| l.cmp(r)).collect::<Vec<_>>();
assert_eq!(expected_result, actual_result);
}
#[test]
fn first_right_then_left() {
let left: Vec<u32> = vec![4, 5, 6];
let right: Vec<u32> = vec![1, 2, 3];
let expected_result: Vec<EitherOrBoth<u32>> = vec![
EitherOrBoth::Right(1),
EitherOrBoth::Right(2),
EitherOrBoth::Right(3),
EitherOrBoth::Left(4),
EitherOrBoth::Left(5),
EitherOrBoth::Left(6),
];
let actual_result = merge_join_by(left, right, |l, r| l.cmp(r)).collect::<Vec<_>>();
assert_eq!(expected_result, actual_result);
}
#[test]
fn interspersed_left_and_right() {
let left: Vec<u32> = vec![1, 3, 5];
let right: Vec<u32> = vec![2, 4, 6];
let expected_result: Vec<EitherOrBoth<u32>> = vec![
EitherOrBoth::Left(1),
EitherOrBoth::Right(2),
EitherOrBoth::Left(3),
EitherOrBoth::Right(4),
EitherOrBoth::Left(5),
EitherOrBoth::Right(6),
];
let actual_result = merge_join_by(left, right, |l, r| l.cmp(r)).collect::<Vec<_>>();
assert_eq!(expected_result, actual_result);
}
#[test]
fn overlapping_left_and_right() {
let left: Vec<u32> = vec![1, 3, 4, 6];
let right: Vec<u32> = vec![2, 3, 4, 5];
let expected_result: Vec<EitherOrBoth<u32>> = vec![
EitherOrBoth::Left(1),
EitherOrBoth::Right(2),
EitherOrBoth::Both(3, 3),
EitherOrBoth::Both(4, 4),
EitherOrBoth::Right(5),
EitherOrBoth::Left(6),
];
let actual_result = merge_join_by(left, right, |l, r| l.cmp(r)).collect::<Vec<_>>();
assert_eq!(expected_result, actual_result);
}

View File

@@ -0,0 +1,69 @@
use itertools::Itertools;
use itertools::{put_back, put_back_n};
#[test]
fn peeking_take_while_peekable() {
let mut r = (0..10).peekable();
r.peeking_take_while(|x| *x <= 3).count();
assert_eq!(r.next(), Some(4));
}
#[test]
fn peeking_take_while_put_back() {
let mut r = put_back(0..10);
r.peeking_take_while(|x| *x <= 3).count();
assert_eq!(r.next(), Some(4));
r.peeking_take_while(|_| true).count();
assert_eq!(r.next(), None);
}
#[test]
fn peeking_take_while_put_back_n() {
let mut r = put_back_n(6..10);
for elt in (0..6).rev() {
r.put_back(elt);
}
r.peeking_take_while(|x| *x <= 3).count();
assert_eq!(r.next(), Some(4));
r.peeking_take_while(|_| true).count();
assert_eq!(r.next(), None);
}
#[test]
fn peeking_take_while_slice_iter() {
let v = [1, 2, 3, 4, 5, 6];
let mut r = v.iter();
r.peeking_take_while(|x| **x <= 3).count();
assert_eq!(r.next(), Some(&4));
r.peeking_take_while(|_| true).count();
assert_eq!(r.next(), None);
}
#[test]
fn peeking_take_while_slice_iter_rev() {
let v = [1, 2, 3, 4, 5, 6];
let mut r = v.iter().rev();
r.peeking_take_while(|x| **x >= 3).count();
assert_eq!(r.next(), Some(&2));
r.peeking_take_while(|_| true).count();
assert_eq!(r.next(), None);
}
#[test]
fn peeking_take_while_nested() {
let mut xs = (0..10).peekable();
let ys: Vec<_> = xs
.peeking_take_while(|x| *x < 6)
.peeking_take_while(|x| *x != 3)
.collect();
assert_eq!(ys, vec![0, 1, 2]);
assert_eq!(xs.next(), Some(3));
let mut xs = (4..10).peekable();
let ys: Vec<_> = xs
.peeking_take_while(|x| *x != 3)
.peeking_take_while(|x| *x < 6)
.collect();
assert_eq!(ys, vec![4, 5]);
assert_eq!(xs.next(), Some(6));
}

1969
vendor/itertools/tests/quick.rs vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,603 @@
//! Test specializations of methods with default impls match the behavior of the
//! default impls.
//!
//! **NOTE:** Due to performance limitations, these tests are not run with miri!
//! They cannot be relied upon to discover soundness issues.
#![cfg(not(miri))]
#![allow(unstable_name_collisions)]
use itertools::Itertools;
use quickcheck::Arbitrary;
use quickcheck::{quickcheck, TestResult};
use rand::Rng;
use std::fmt::Debug;
struct Unspecialized<I>(I);
impl<I> Iterator for Unspecialized<I>
where
I: Iterator,
{
type Item = I::Item;
#[inline(always)]
fn next(&mut self) -> Option<Self::Item> {
self.0.next()
}
}
impl<I> DoubleEndedIterator for Unspecialized<I>
where
I: DoubleEndedIterator,
{
#[inline(always)]
fn next_back(&mut self) -> Option<Self::Item> {
self.0.next_back()
}
}
fn test_specializations<I>(it: &I)
where
I::Item: Eq + Debug + Clone,
I: Iterator + Clone,
{
macro_rules! check_specialized {
($src:expr, |$it:pat| $closure:expr) => {
// Many iterators special-case the first elements, so we test specializations for iterators that have already been advanced.
let mut src = $src.clone();
for _ in 0..5 {
let $it = src.clone();
let v1 = $closure;
let $it = Unspecialized(src.clone());
let v2 = $closure;
assert_eq!(v1, v2);
src.next();
}
}
}
check_specialized!(it, |i| i.count());
check_specialized!(it, |i| i.last());
check_specialized!(it, |i| i.collect::<Vec<_>>());
check_specialized!(it, |i| {
let mut parameters_from_fold = vec![];
let fold_result = i.fold(vec![], |mut acc, v: I::Item| {
parameters_from_fold.push((acc.clone(), v.clone()));
acc.push(v);
acc
});
(parameters_from_fold, fold_result)
});
check_specialized!(it, |mut i| {
let mut parameters_from_all = vec![];
let first = i.next();
let all_result = i.all(|x| {
parameters_from_all.push(x.clone());
Some(x) == first
});
(parameters_from_all, all_result)
});
let size = it.clone().count();
for n in 0..size + 2 {
check_specialized!(it, |mut i| i.nth(n));
}
// size_hint is a bit harder to check
let mut it_sh = it.clone();
for n in 0..size + 2 {
let len = it_sh.clone().count();
let (min, max) = it_sh.size_hint();
assert_eq!(size - n.min(size), len);
assert!(min <= len);
if let Some(max) = max {
assert!(len <= max);
}
it_sh.next();
}
}
fn test_double_ended_specializations<I>(it: &I)
where
I::Item: Eq + Debug + Clone,
I: DoubleEndedIterator + Clone,
{
macro_rules! check_specialized {
($src:expr, |$it:pat| $closure:expr) => {
// Many iterators special-case the first elements, so we test specializations for iterators that have already been advanced.
let mut src = $src.clone();
for step in 0..8 {
let $it = src.clone();
let v1 = $closure;
let $it = Unspecialized(src.clone());
let v2 = $closure;
assert_eq!(v1, v2);
if step % 2 == 0 {
src.next();
} else {
src.next_back();
}
}
}
}
check_specialized!(it, |i| {
let mut parameters_from_rfold = vec![];
let rfold_result = i.rfold(vec![], |mut acc, v: I::Item| {
parameters_from_rfold.push((acc.clone(), v.clone()));
acc.push(v);
acc
});
(parameters_from_rfold, rfold_result)
});
let size = it.clone().count();
for n in 0..size + 2 {
check_specialized!(it, |mut i| i.nth_back(n));
}
}
quickcheck! {
fn interleave(v: Vec<u8>, w: Vec<u8>) -> () {
test_specializations(&v.iter().interleave(w.iter()));
}
fn interleave_shortest(v: Vec<u8>, w: Vec<u8>) -> () {
test_specializations(&v.iter().interleave_shortest(w.iter()));
}
fn batching(v: Vec<u8>) -> () {
test_specializations(&v.iter().batching(Iterator::next));
}
fn tuple_windows(v: Vec<u8>) -> () {
test_specializations(&v.iter().tuple_windows::<(_,)>());
test_specializations(&v.iter().tuple_windows::<(_, _)>());
test_specializations(&v.iter().tuple_windows::<(_, _, _)>());
}
fn circular_tuple_windows(v: Vec<u8>) -> () {
test_specializations(&v.iter().circular_tuple_windows::<(_,)>());
test_specializations(&v.iter().circular_tuple_windows::<(_, _)>());
test_specializations(&v.iter().circular_tuple_windows::<(_, _, _)>());
}
fn tuples(v: Vec<u8>) -> () {
test_specializations(&v.iter().tuples::<(_,)>());
test_specializations(&v.iter().tuples::<(_, _)>());
test_specializations(&v.iter().tuples::<(_, _, _)>());
}
fn cartesian_product(a: Vec<u8>, b: Vec<u8>) -> TestResult {
if a.len() * b.len() > 100 {
return TestResult::discard();
}
test_specializations(&a.iter().cartesian_product(&b));
TestResult::passed()
}
fn multi_cartesian_product(a: Vec<u8>, b: Vec<u8>, c: Vec<u8>) -> TestResult {
if a.len() * b.len() * c.len() > 100 {
return TestResult::discard();
}
test_specializations(&vec![a, b, c].into_iter().multi_cartesian_product());
TestResult::passed()
}
fn coalesce(v: Vec<u8>) -> () {
test_specializations(&v.iter().coalesce(|x, y| if x == y { Ok(x) } else { Err((x, y)) }))
}
fn dedup(v: Vec<u8>) -> () {
test_specializations(&v.iter().dedup())
}
fn dedup_by(v: Vec<u8>) -> () {
test_specializations(&v.iter().dedup_by(PartialOrd::ge))
}
fn dedup_with_count(v: Vec<u8>) -> () {
test_specializations(&v.iter().dedup_with_count())
}
fn dedup_by_with_count(v: Vec<u8>) -> () {
test_specializations(&v.iter().dedup_by_with_count(PartialOrd::ge))
}
fn duplicates(v: Vec<u8>) -> () {
let it = v.iter().duplicates();
test_specializations(&it);
test_double_ended_specializations(&it);
}
fn duplicates_by(v: Vec<u8>) -> () {
let it = v.iter().duplicates_by(|x| *x % 10);
test_specializations(&it);
test_double_ended_specializations(&it);
}
fn unique(v: Vec<u8>) -> () {
let it = v.iter().unique();
test_specializations(&it);
test_double_ended_specializations(&it);
}
fn unique_by(v: Vec<u8>) -> () {
let it = v.iter().unique_by(|x| *x % 50);
test_specializations(&it);
test_double_ended_specializations(&it);
}
fn take_while_inclusive(v: Vec<u8>) -> () {
test_specializations(&v.iter().copied().take_while_inclusive(|&x| x < 100));
}
fn while_some(v: Vec<u8>) -> () {
test_specializations(&v.iter().map(|&x| if x < 100 { Some(2 * x) } else { None }).while_some());
}
fn pad_using(v: Vec<u8>) -> () {
use std::convert::TryFrom;
let it = v.iter().copied().pad_using(10, |i| u8::try_from(5 * i).unwrap_or(u8::MAX));
test_specializations(&it);
test_double_ended_specializations(&it);
}
fn with_position(v: Vec<u8>) -> () {
test_specializations(&v.iter().with_position());
}
fn positions(v: Vec<u8>) -> () {
let it = v.iter().positions(|x| x % 5 == 0);
test_specializations(&it);
test_double_ended_specializations(&it);
}
fn update(v: Vec<u8>) -> () {
let it = v.iter().copied().update(|x| *x = x.wrapping_mul(7));
test_specializations(&it);
test_double_ended_specializations(&it);
}
fn tuple_combinations(v: Vec<u8>) -> TestResult {
if v.len() > 10 {
return TestResult::discard();
}
test_specializations(&v.iter().tuple_combinations::<(_,)>());
test_specializations(&v.iter().tuple_combinations::<(_, _)>());
test_specializations(&v.iter().tuple_combinations::<(_, _, _)>());
TestResult::passed()
}
fn intersperse(v: Vec<u8>) -> () {
test_specializations(&v.into_iter().intersperse(0));
}
fn intersperse_with(v: Vec<u8>) -> () {
test_specializations(&v.into_iter().intersperse_with(|| 0));
}
fn array_combinations(v: Vec<u8>) -> TestResult {
if v.len() > 10 {
return TestResult::discard();
}
test_specializations(&v.iter().array_combinations::<1>());
test_specializations(&v.iter().array_combinations::<2>());
test_specializations(&v.iter().array_combinations::<3>());
TestResult::passed()
}
fn combinations(a: Vec<u8>, n: u8) -> TestResult {
if n > 3 || a.len() > 8 {
return TestResult::discard();
}
test_specializations(&a.iter().combinations(n as usize));
TestResult::passed()
}
fn combinations_with_replacement(a: Vec<u8>, n: u8) -> TestResult {
if n > 3 || a.len() > 7 {
return TestResult::discard();
}
test_specializations(&a.iter().combinations_with_replacement(n as usize));
TestResult::passed()
}
fn permutations(a: Vec<u8>, n: u8) -> TestResult {
if n > 3 || a.len() > 8 {
return TestResult::discard();
}
test_specializations(&a.iter().permutations(n as usize));
TestResult::passed()
}
fn powerset(a: Vec<u8>) -> TestResult {
if a.len() > 6 {
return TestResult::discard();
}
test_specializations(&a.iter().powerset());
TestResult::passed()
}
fn zip_longest(a: Vec<u8>, b: Vec<u8>) -> () {
let it = a.into_iter().zip_longest(b);
test_specializations(&it);
test_double_ended_specializations(&it);
}
fn zip_eq(a: Vec<u8>) -> () {
test_specializations(&a.iter().zip_eq(a.iter().rev()))
}
fn multizip(a: Vec<u8>) -> () {
let it = itertools::multizip((a.iter(), a.iter().rev(), a.iter().take(50)));
test_specializations(&it);
test_double_ended_specializations(&it);
}
fn izip(a: Vec<u8>, b: Vec<u8>) -> () {
test_specializations(&itertools::izip!(b.iter(), a, b.iter().rev()));
}
fn iproduct(a: Vec<u8>, b: Vec<u8>, c: Vec<u8>) -> TestResult {
if a.len() * b.len() * c.len() > 200 {
return TestResult::discard();
}
test_specializations(&itertools::iproduct!(a, b.iter(), c));
TestResult::passed()
}
fn repeat_n(element: i8, n: u8) -> () {
let it = itertools::repeat_n(element, n as usize);
test_specializations(&it);
test_double_ended_specializations(&it);
}
fn exactly_one_error(v: Vec<u8>) -> TestResult {
// Use `at_most_one` would be similar.
match v.iter().exactly_one() {
Ok(_) => TestResult::discard(),
Err(it) => {
test_specializations(&it);
TestResult::passed()
}
}
}
}
quickcheck! {
fn put_back_qc(test_vec: Vec<i32>) -> () {
test_specializations(&itertools::put_back(test_vec.iter()));
let mut pb = itertools::put_back(test_vec.into_iter());
pb.put_back(1);
test_specializations(&pb);
}
fn put_back_n(v: Vec<u8>, n: u8) -> () {
let mut it = itertools::put_back_n(v);
for k in 0..n {
it.put_back(k);
}
test_specializations(&it);
}
fn multipeek(v: Vec<u8>, n: u8) -> () {
let mut it = v.into_iter().multipeek();
for _ in 0..n {
it.peek();
}
test_specializations(&it);
}
fn peek_nth_with_peek(v: Vec<u8>, n: u8) -> () {
let mut it = itertools::peek_nth(v);
for _ in 0..n {
it.peek();
}
test_specializations(&it);
}
fn peek_nth_with_peek_nth(v: Vec<u8>, n: u8) -> () {
let mut it = itertools::peek_nth(v);
it.peek_nth(n as usize);
test_specializations(&it);
}
fn peek_nth_with_peek_mut(v: Vec<u8>, n: u8) -> () {
let mut it = itertools::peek_nth(v);
for _ in 0..n {
if let Some(x) = it.peek_mut() {
*x = x.wrapping_add(50);
}
}
test_specializations(&it);
}
fn peek_nth_with_peek_nth_mut(v: Vec<u8>, n: u8) -> () {
let mut it = itertools::peek_nth(v);
if let Some(x) = it.peek_nth_mut(n as usize) {
*x = x.wrapping_add(50);
}
test_specializations(&it);
}
}
quickcheck! {
fn merge(a: Vec<u8>, b: Vec<u8>) -> () {
test_specializations(&a.into_iter().merge(b))
}
fn merge_by(a: Vec<u8>, b: Vec<u8>) -> () {
test_specializations(&a.into_iter().merge_by(b, PartialOrd::ge))
}
fn merge_join_by_ordering(i1: Vec<u8>, i2: Vec<u8>) -> () {
test_specializations(&i1.into_iter().merge_join_by(i2, Ord::cmp));
}
fn merge_join_by_bool(i1: Vec<u8>, i2: Vec<u8>) -> () {
test_specializations(&i1.into_iter().merge_join_by(i2, PartialOrd::ge));
}
fn kmerge(a: Vec<i8>, b: Vec<i8>, c: Vec<i8>) -> () {
test_specializations(&vec![a, b, c]
.into_iter()
.map(|v| v.into_iter().sorted())
.kmerge());
}
fn kmerge_by(a: Vec<i8>, b: Vec<i8>, c: Vec<i8>) -> () {
test_specializations(&vec![a, b, c]
.into_iter()
.map(|v| v.into_iter().sorted_by_key(|a| a.abs()))
.kmerge_by(|a, b| a.abs() < b.abs()));
}
}
quickcheck! {
fn map_into(v: Vec<u8>) -> () {
let it = v.into_iter().map_into::<u32>();
test_specializations(&it);
test_double_ended_specializations(&it);
}
fn map_ok(v: Vec<Result<u8, char>>) -> () {
let it = v.into_iter().map_ok(|u| u.checked_add(1));
test_specializations(&it);
test_double_ended_specializations(&it);
}
fn filter_ok(v: Vec<Result<u8, char>>) -> () {
let it = v.into_iter().filter_ok(|&i| i < 20);
test_specializations(&it);
test_double_ended_specializations(&it);
}
fn filter_map_ok(v: Vec<Result<u8, char>>) -> () {
let it = v.into_iter().filter_map_ok(|i| if i < 20 { Some(i * 2) } else { None });
test_specializations(&it);
test_double_ended_specializations(&it);
}
// `SmallIter2<u8>` because `Vec<u8>` is too slow and we get bad coverage from a singleton like Option<u8>
fn flatten_ok(v: Vec<Result<SmallIter2<u8>, char>>) -> () {
let it = v.into_iter().flatten_ok();
test_specializations(&it);
test_double_ended_specializations(&it);
}
}
quickcheck! {
// TODO Replace this function by a normal call to test_specializations
fn process_results(v: Vec<Result<u8, u8>>) -> () {
helper(v.iter().copied());
helper(v.iter().copied().filter(Result::is_ok));
fn helper(it: impl DoubleEndedIterator<Item = Result<u8, u8>> + Clone) {
macro_rules! check_results_specialized {
($src:expr, |$it:pat| $closure:expr) => {
assert_eq!(
itertools::process_results($src.clone(), |$it| $closure),
itertools::process_results($src.clone(), |i| {
let $it = Unspecialized(i);
$closure
}),
)
}
}
check_results_specialized!(it, |i| i.count());
check_results_specialized!(it, |i| i.last());
check_results_specialized!(it, |i| i.collect::<Vec<_>>());
check_results_specialized!(it, |i| i.rev().collect::<Vec<_>>());
check_results_specialized!(it, |i| {
let mut parameters_from_fold = vec![];
let fold_result = i.fold(vec![], |mut acc, v| {
parameters_from_fold.push((acc.clone(), v));
acc.push(v);
acc
});
(parameters_from_fold, fold_result)
});
check_results_specialized!(it, |i| {
let mut parameters_from_rfold = vec![];
let rfold_result = i.rfold(vec![], |mut acc, v| {
parameters_from_rfold.push((acc.clone(), v));
acc.push(v);
acc
});
(parameters_from_rfold, rfold_result)
});
check_results_specialized!(it, |mut i| {
let mut parameters_from_all = vec![];
let first = i.next();
let all_result = i.all(|x| {
parameters_from_all.push(x);
Some(x)==first
});
(parameters_from_all, all_result)
});
let size = it.clone().count();
for n in 0..size + 2 {
check_results_specialized!(it, |mut i| i.nth(n));
}
for n in 0..size + 2 {
check_results_specialized!(it, |mut i| i.nth_back(n));
}
}
}
}
/// Like `VecIntoIter<T>` with maximum 2 elements.
#[derive(Debug, Clone, Default)]
enum SmallIter2<T> {
#[default]
Zero,
One(T),
Two(T, T),
}
impl<T: Arbitrary> Arbitrary for SmallIter2<T> {
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
match g.gen_range(0u8, 3) {
0 => Self::Zero,
1 => Self::One(T::arbitrary(g)),
2 => Self::Two(T::arbitrary(g), T::arbitrary(g)),
_ => unreachable!(),
}
}
// maybe implement shrink too, maybe not
}
impl<T> Iterator for SmallIter2<T> {
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
match std::mem::take(self) {
Self::Zero => None,
Self::One(val) => Some(val),
Self::Two(val, second) => {
*self = Self::One(second);
Some(val)
}
}
}
fn size_hint(&self) -> (usize, Option<usize>) {
let len = match self {
Self::Zero => 0,
Self::One(_) => 1,
Self::Two(_, _) => 2,
};
(len, Some(len))
}
}
impl<T> DoubleEndedIterator for SmallIter2<T> {
fn next_back(&mut self) -> Option<Self::Item> {
match std::mem::take(self) {
Self::Zero => None,
Self::One(val) => Some(val),
Self::Two(first, val) => {
*self = Self::One(first);
Some(val)
}
}
}
}

399
vendor/itertools/tests/test_core.rs vendored Normal file
View File

@@ -0,0 +1,399 @@
//! Licensed under the Apache License, Version 2.0
//! https://www.apache.org/licenses/LICENSE-2.0 or the MIT license
//! https://opensource.org/licenses/MIT, at your
//! option. This file may not be copied, modified, or distributed
//! except according to those terms.
#![no_std]
#![allow(deprecated)]
use crate::it::chain;
use crate::it::free::put_back;
use crate::it::interleave;
use crate::it::intersperse;
use crate::it::intersperse_with;
use crate::it::iproduct;
use crate::it::izip;
use crate::it::multizip;
use crate::it::Itertools;
use core::iter;
use itertools as it;
#[allow(dead_code)]
fn get_esi_then_esi<I: ExactSizeIterator + Clone>(it: I) {
fn is_esi(_: impl ExactSizeIterator) {}
is_esi(it.clone().get(1..4));
is_esi(it.clone().get(1..=4));
is_esi(it.clone().get(1..));
is_esi(it.clone().get(..4));
is_esi(it.clone().get(..=4));
is_esi(it.get(..));
}
#[allow(dead_code)]
fn get_dei_esi_then_dei_esi<I: DoubleEndedIterator + ExactSizeIterator + Clone>(it: I) {
fn is_dei_esi(_: impl DoubleEndedIterator + ExactSizeIterator) {}
is_dei_esi(it.clone().get(1..4));
is_dei_esi(it.clone().get(1..=4));
is_dei_esi(it.clone().get(1..));
is_dei_esi(it.clone().get(..4));
is_dei_esi(it.clone().get(..=4));
is_dei_esi(it.get(..));
}
#[test]
fn get_1_max() {
let mut it = (0..5).get(1..=usize::MAX);
assert_eq!(it.next(), Some(1));
assert_eq!(it.next_back(), Some(4));
}
#[test]
#[should_panic]
fn get_full_range_inclusive() {
let _it = (0..5).get(0..=usize::MAX);
}
#[test]
fn product0() {
let mut prod = iproduct!();
assert_eq!(prod.next(), Some(()));
assert!(prod.next().is_none());
}
#[test]
fn iproduct1() {
let s = "αβ";
let mut prod = iproduct!(s.chars());
assert_eq!(prod.next(), Some(('α',)));
assert_eq!(prod.next(), Some(('β',)));
assert!(prod.next().is_none());
}
#[test]
fn product2() {
let s = "αβ";
let mut prod = iproduct!(s.chars(), 0..2);
assert!(prod.next() == Some(('α', 0)));
assert!(prod.next() == Some(('α', 1)));
assert!(prod.next() == Some(('β', 0)));
assert!(prod.next() == Some(('β', 1)));
assert!(prod.next().is_none());
}
#[test]
fn product_temporary() {
for (_x, _y, _z) in iproduct!(
[0, 1, 2].iter().cloned(),
[0, 1, 2].iter().cloned(),
[0, 1, 2].iter().cloned()
) {
// ok
}
}
#[test]
fn izip_macro() {
let mut zip = izip!(2..3);
assert!(zip.next() == Some(2));
assert!(zip.next().is_none());
let mut zip = izip!(0..3, 0..2, 0..2i8);
for i in 0..2 {
assert!((i as usize, i, i as i8) == zip.next().unwrap());
}
assert!(zip.next().is_none());
let xs: [isize; 0] = [];
let mut zip = izip!(0..3, 0..2, 0..2i8, &xs);
assert!(zip.next().is_none());
}
#[test]
fn izip2() {
let _zip1: iter::Zip<_, _> = izip!(1.., 2..);
let _zip2: iter::Zip<_, _> = izip!(1.., 2..,);
}
#[test]
fn izip3() {
let mut zip: iter::Map<iter::Zip<_, _>, _> = izip!(0..3, 0..2, 0..2i8);
for i in 0..2 {
assert!((i as usize, i, i as i8) == zip.next().unwrap());
}
assert!(zip.next().is_none());
}
#[test]
fn multizip3() {
let mut zip = multizip((0..3, 0..2, 0..2i8));
for i in 0..2 {
assert!((i as usize, i, i as i8) == zip.next().unwrap());
}
assert!(zip.next().is_none());
let xs: [isize; 0] = [];
let mut zip = multizip((0..3, 0..2, 0..2i8, xs.iter()));
assert!(zip.next().is_none());
for (_, _, _, _, _) in multizip((0..3, 0..2, xs.iter(), &xs, xs.to_vec())) {
/* test compiles */
}
}
#[test]
fn chain_macro() {
let mut chain = chain!(2..3);
assert!(chain.next() == Some(2));
assert!(chain.next().is_none());
let mut chain = chain!(0..2, 2..3, 3..5i8);
for i in 0..5i8 {
assert_eq!(Some(i), chain.next());
}
assert!(chain.next().is_none());
let mut chain = chain!();
assert_eq!(chain.next(), Option::<()>::None);
}
#[test]
fn chain2() {
let _ = chain!(1.., 2..);
let _ = chain!(1.., 2..,);
}
#[test]
fn write_to() {
let xs = [7, 9, 8];
let mut ys = [0; 5];
let cnt = ys.iter_mut().set_from(xs.iter().copied());
assert!(cnt == xs.len());
assert!(ys == [7, 9, 8, 0, 0]);
let cnt = ys.iter_mut().set_from(0..10);
assert!(cnt == ys.len());
assert!(ys == [0, 1, 2, 3, 4]);
}
#[test]
fn test_interleave() {
let xs: [u8; 0] = [];
let ys = [7u8, 9, 8, 10];
let zs = [2u8, 77];
let it = interleave(xs.iter(), ys.iter());
it::assert_equal(it, ys.iter());
let rs = [7u8, 2, 9, 77, 8, 10];
let it = interleave(ys.iter(), zs.iter());
it::assert_equal(it, rs.iter());
}
#[test]
fn test_intersperse() {
let xs = [1u8, 2, 3];
let ys = [1u8, 0, 2, 0, 3];
let it = intersperse(&xs, &0);
it::assert_equal(it, ys.iter());
}
#[test]
fn test_intersperse_with() {
let xs = [1u8, 2, 3];
let ys = [1u8, 10, 2, 10, 3];
let i = 10;
let it = intersperse_with(&xs, || &i);
it::assert_equal(it, ys.iter());
}
#[test]
fn dropping() {
let xs = [1, 2, 3];
let mut it = xs.iter().dropping(2);
assert_eq!(it.next(), Some(&3));
assert!(it.next().is_none());
let mut it = xs.iter().dropping(5);
assert!(it.next().is_none());
}
#[test]
fn batching() {
let xs = [0, 1, 2, 1, 3];
let ys = [(0, 1), (2, 1)];
// An iterator that gathers elements up in pairs
let pit = xs
.iter()
.cloned()
.batching(|it| it.next().and_then(|x| it.next().map(|y| (x, y))));
it::assert_equal(pit, ys.iter().cloned());
}
#[test]
fn test_put_back() {
let xs = [0, 1, 1, 1, 2, 1, 3, 3];
let mut pb = put_back(xs.iter().cloned());
pb.next();
pb.put_back(1);
pb.put_back(0);
it::assert_equal(pb, xs.iter().cloned());
}
#[test]
fn merge() {
it::assert_equal((0..10).step_by(2).merge((1..10).step_by(2)), 0..10);
}
#[test]
fn repeatn() {
let s = "α";
let mut it = it::repeat_n(s, 3);
assert_eq!(it.len(), 3);
assert_eq!(it.next(), Some(s));
assert_eq!(it.next(), Some(s));
assert_eq!(it.next(), Some(s));
assert_eq!(it.next(), None);
assert_eq!(it.next(), None);
}
#[test]
fn count_clones() {
// Check that RepeatN only clones N - 1 times.
use core::cell::Cell;
#[derive(PartialEq, Debug)]
struct Foo {
n: Cell<usize>,
}
impl Clone for Foo {
fn clone(&self) -> Self {
let n = self.n.get();
self.n.set(n + 1);
Self {
n: Cell::new(n + 1),
}
}
}
for n in 0..10 {
let f = Foo { n: Cell::new(0) };
let it = it::repeat_n(f, n);
// drain it
let last = it.last();
if n == 0 {
assert_eq!(last, None);
} else {
assert_eq!(
last,
Some(Foo {
n: Cell::new(n - 1)
})
);
}
}
}
#[test]
fn part() {
let mut data = [7, 1, 1, 9, 1, 1, 3];
let i = it::partition(&mut data, |elt| *elt >= 3);
assert_eq!(i, 3);
assert_eq!(data, [7, 3, 9, 1, 1, 1, 1]);
let i = it::partition(&mut data, |elt| *elt == 1);
assert_eq!(i, 4);
assert_eq!(data, [1, 1, 1, 1, 9, 3, 7]);
let mut data = [1, 2, 3, 4, 5, 6, 7, 8, 9];
let i = it::partition(&mut data, |elt| *elt % 3 == 0);
assert_eq!(i, 3);
assert_eq!(data, [9, 6, 3, 4, 5, 2, 7, 8, 1]);
}
#[test]
fn tree_reduce() {
for i in 0..100 {
assert_eq!((0..i).tree_reduce(|x, y| x + y), (0..i).fold1(|x, y| x + y));
}
}
#[test]
fn exactly_one() {
assert_eq!((0..10).filter(|&x| x == 2).exactly_one().unwrap(), 2);
assert!((0..10)
.filter(|&x| x > 1 && x < 4)
.exactly_one()
.unwrap_err()
.eq(2..4));
assert!((0..10)
.filter(|&x| x > 1 && x < 5)
.exactly_one()
.unwrap_err()
.eq(2..5));
assert!((0..10)
.filter(|&_| false)
.exactly_one()
.unwrap_err()
.eq(0..0));
}
#[test]
fn at_most_one() {
assert_eq!((0..10).filter(|&x| x == 2).at_most_one().unwrap(), Some(2));
assert!((0..10)
.filter(|&x| x > 1 && x < 4)
.at_most_one()
.unwrap_err()
.eq(2..4));
assert!((0..10)
.filter(|&x| x > 1 && x < 5)
.at_most_one()
.unwrap_err()
.eq(2..5));
assert_eq!((0..10).filter(|&_| false).at_most_one().unwrap(), None);
}
#[test]
fn sum1() {
let v: &[i32] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
assert_eq!(v[..0].iter().cloned().sum1::<i32>(), None);
assert_eq!(v[1..2].iter().cloned().sum1::<i32>(), Some(1));
assert_eq!(v[1..3].iter().cloned().sum1::<i32>(), Some(3));
assert_eq!(v.iter().cloned().sum1::<i32>(), Some(55));
}
#[test]
fn product1() {
let v: &[i32] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
assert_eq!(v[..0].iter().cloned().product1::<i32>(), None);
assert_eq!(v[..1].iter().cloned().product1::<i32>(), Some(0));
assert_eq!(v[1..3].iter().cloned().product1::<i32>(), Some(2));
assert_eq!(v[1..5].iter().cloned().product1::<i32>(), Some(24));
}
#[test]
fn next_array() {
let v = [1, 2, 3, 4, 5];
let mut iter = v.iter();
assert_eq!(iter.next_array(), Some([]));
assert_eq!(iter.next_array().map(|[&x, &y]| [x, y]), Some([1, 2]));
assert_eq!(iter.next_array().map(|[&x, &y]| [x, y]), Some([3, 4]));
assert_eq!(iter.next_array::<2>(), None);
}
#[test]
fn collect_array() {
let v = [1, 2];
let iter = v.iter().cloned();
assert_eq!(iter.collect_array(), Some([1, 2]));
let v = [1];
let iter = v.iter().cloned();
assert_eq!(iter.collect_array::<2>(), None);
let v = [1, 2, 3];
let iter = v.iter().cloned();
assert_eq!(iter.collect_array::<2>(), None);
}

1569
vendor/itertools/tests/test_std.rs vendored Normal file

File diff suppressed because it is too large Load Diff

86
vendor/itertools/tests/tuples.rs vendored Normal file
View File

@@ -0,0 +1,86 @@
use itertools::Itertools;
#[test]
fn tuples() {
let v = [1, 2, 3, 4, 5];
let mut iter = v.iter().cloned().tuples();
assert_eq!(Some((1,)), iter.next());
assert_eq!(Some((2,)), iter.next());
assert_eq!(Some((3,)), iter.next());
assert_eq!(Some((4,)), iter.next());
assert_eq!(Some((5,)), iter.next());
assert_eq!(None, iter.next());
assert_eq!(None, iter.into_buffer().next());
let mut iter = v.iter().cloned().tuples();
assert_eq!(Some((1, 2)), iter.next());
assert_eq!(Some((3, 4)), iter.next());
assert_eq!(None, iter.next());
itertools::assert_equal(vec![5], iter.into_buffer());
let mut iter = v.iter().cloned().tuples();
assert_eq!(Some((1, 2, 3)), iter.next());
assert_eq!(None, iter.next());
itertools::assert_equal(vec![4, 5], iter.into_buffer());
let mut iter = v.iter().cloned().tuples();
assert_eq!(Some((1, 2, 3, 4)), iter.next());
assert_eq!(None, iter.next());
itertools::assert_equal(vec![5], iter.into_buffer());
}
#[test]
fn tuple_windows() {
let v = [1, 2, 3, 4, 5];
let mut iter = v.iter().cloned().tuple_windows();
assert_eq!(Some((1,)), iter.next());
assert_eq!(Some((2,)), iter.next());
assert_eq!(Some((3,)), iter.next());
let mut iter = v.iter().cloned().tuple_windows();
assert_eq!(Some((1, 2)), iter.next());
assert_eq!(Some((2, 3)), iter.next());
assert_eq!(Some((3, 4)), iter.next());
assert_eq!(Some((4, 5)), iter.next());
assert_eq!(None, iter.next());
let mut iter = v.iter().cloned().tuple_windows();
assert_eq!(Some((1, 2, 3)), iter.next());
assert_eq!(Some((2, 3, 4)), iter.next());
assert_eq!(Some((3, 4, 5)), iter.next());
assert_eq!(None, iter.next());
let mut iter = v.iter().cloned().tuple_windows();
assert_eq!(Some((1, 2, 3, 4)), iter.next());
assert_eq!(Some((2, 3, 4, 5)), iter.next());
assert_eq!(None, iter.next());
let v = [1, 2, 3];
let mut iter = v.iter().cloned().tuple_windows::<(_, _, _, _)>();
assert_eq!(None, iter.next());
}
#[test]
fn next_tuple() {
let v = [1, 2, 3, 4, 5];
let mut iter = v.iter();
assert_eq!(iter.next_tuple().map(|(&x, &y)| (x, y)), Some((1, 2)));
assert_eq!(iter.next_tuple().map(|(&x, &y)| (x, y)), Some((3, 4)));
assert_eq!(iter.next_tuple::<(_, _)>(), None);
}
#[test]
fn collect_tuple() {
let v = [1, 2];
let iter = v.iter().cloned();
assert_eq!(iter.collect_tuple(), Some((1, 2)));
let v = [1];
let iter = v.iter().cloned();
assert_eq!(iter.collect_tuple::<(_, _)>(), None);
let v = [1, 2, 3];
let iter = v.iter().cloned();
assert_eq!(iter.collect_tuple::<(_, _)>(), None);
}

56
vendor/itertools/tests/zip.rs vendored Normal file
View File

@@ -0,0 +1,56 @@
use itertools::multizip;
use itertools::EitherOrBoth::{Both, Left, Right};
use itertools::Itertools;
#[test]
fn zip_longest_fused() {
let a = [Some(1), None, Some(3), Some(4)];
let b = [1, 2, 3];
let unfused = a
.iter()
.batching(|it| *it.next().unwrap())
.zip_longest(b.iter().cloned());
itertools::assert_equal(unfused, vec![Both(1, 1), Right(2), Right(3)]);
}
#[test]
fn test_zip_longest_size_hint() {
let c = (1..10).cycle();
let v: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
let v2 = &[10, 11, 12];
assert_eq!(c.zip_longest(v.iter()).size_hint(), (usize::MAX, None));
assert_eq!(v.iter().zip_longest(v2.iter()).size_hint(), (10, Some(10)));
}
#[test]
fn test_double_ended_zip_longest() {
let xs = [1, 2, 3, 4, 5, 6];
let ys = [1, 2, 3, 7];
let a = xs.iter().copied();
let b = ys.iter().copied();
let mut it = a.zip_longest(b);
assert_eq!(it.next(), Some(Both(1, 1)));
assert_eq!(it.next(), Some(Both(2, 2)));
assert_eq!(it.next_back(), Some(Left(6)));
assert_eq!(it.next_back(), Some(Left(5)));
assert_eq!(it.next_back(), Some(Both(4, 7)));
assert_eq!(it.next(), Some(Both(3, 3)));
assert_eq!(it.next(), None);
}
#[test]
fn test_double_ended_zip() {
let xs = [1, 2, 3, 4, 5, 6];
let ys = [1, 2, 3, 7];
let a = xs.iter().copied();
let b = ys.iter().copied();
let mut it = multizip((a, b));
assert_eq!(it.next_back(), Some((4, 7)));
assert_eq!(it.next_back(), Some((3, 3)));
assert_eq!(it.next_back(), Some((2, 2)));
assert_eq!(it.next_back(), Some((1, 1)));
assert_eq!(it.next_back(), None);
}