summaryrefslogtreecommitdiffstats
path: root/vendor/itertools/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /vendor/itertools/tests
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/itertools/tests')
-rw-r--r--vendor/itertools/tests/peeking_take_while.rs19
-rw-r--r--vendor/itertools/tests/quick.rs100
-rw-r--r--vendor/itertools/tests/test_std.rs20
3 files changed, 137 insertions, 2 deletions
diff --git a/vendor/itertools/tests/peeking_take_while.rs b/vendor/itertools/tests/peeking_take_while.rs
index a1147027e..5be97271d 100644
--- a/vendor/itertools/tests/peeking_take_while.rs
+++ b/vendor/itertools/tests/peeking_take_while.rs
@@ -48,3 +48,22 @@ fn peeking_take_while_slice_iter_rev() {
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));
+}
diff --git a/vendor/itertools/tests/quick.rs b/vendor/itertools/tests/quick.rs
index 0adcf1ad7..c19af6c1e 100644
--- a/vendor/itertools/tests/quick.rs
+++ b/vendor/itertools/tests/quick.rs
@@ -830,6 +830,31 @@ quickcheck! {
}
quickcheck! {
+ fn merge_join_by_ordering_vs_bool(a: Vec<u8>, b: Vec<u8>) -> bool {
+ use either::Either;
+ use itertools::free::merge_join_by;
+ let mut has_equal = false;
+ let it_ord = merge_join_by(a.clone(), b.clone(), Ord::cmp).flat_map(|v| match v {
+ EitherOrBoth::Both(l, r) => {
+ has_equal = true;
+ vec![Either::Left(l), Either::Right(r)]
+ }
+ EitherOrBoth::Left(l) => vec![Either::Left(l)],
+ EitherOrBoth::Right(r) => vec![Either::Right(r)],
+ });
+ let it_bool = merge_join_by(a, b, PartialOrd::le);
+ itertools::equal(it_ord, it_bool) || has_equal
+ }
+ fn merge_join_by_bool_unwrapped_is_merge_by(a: Vec<u8>, b: Vec<u8>) -> bool {
+ use either::Either;
+ use itertools::free::merge_join_by;
+ let it = a.clone().into_iter().merge_by(b.clone(), PartialOrd::ge);
+ let it_join = merge_join_by(a, b, PartialOrd::ge).map(Either::into_inner);
+ itertools::equal(it, it_join)
+ }
+}
+
+quickcheck! {
fn size_tee(a: Vec<u8>) -> bool {
let (mut t1, mut t2) = a.iter().tee();
t1.next();
@@ -994,6 +1019,17 @@ quickcheck! {
}
quickcheck! {
+ fn chunk_clone_equal(a: Vec<u8>, size: u8) -> () {
+ let mut size = size;
+ if size == 0 {
+ size += 1;
+ }
+ let it = a.chunks(size as usize);
+ itertools::assert_equal(it.clone(), it);
+ }
+}
+
+quickcheck! {
fn equal_chunks_lazy(a: Vec<u8>, size: u8) -> bool {
let mut size = size;
if size == 0 {
@@ -1010,7 +1046,71 @@ quickcheck! {
}
}
+// tuple iterators
quickcheck! {
+ fn equal_circular_tuple_windows_1(a: Vec<u8>) -> bool {
+ let x = a.iter().map(|e| (e,) );
+ let y = a.iter().circular_tuple_windows::<(_,)>();
+ itertools::assert_equal(x,y);
+ true
+ }
+
+ fn equal_circular_tuple_windows_2(a: Vec<u8>) -> bool {
+ let x = (0..a.len()).map(|start_idx| (
+ &a[start_idx],
+ &a[(start_idx + 1) % a.len()],
+ ));
+ let y = a.iter().circular_tuple_windows::<(_, _)>();
+ itertools::assert_equal(x,y);
+ true
+ }
+
+ fn equal_circular_tuple_windows_3(a: Vec<u8>) -> bool {
+ let x = (0..a.len()).map(|start_idx| (
+ &a[start_idx],
+ &a[(start_idx + 1) % a.len()],
+ &a[(start_idx + 2) % a.len()],
+ ));
+ let y = a.iter().circular_tuple_windows::<(_, _, _)>();
+ itertools::assert_equal(x,y);
+ true
+ }
+
+ fn equal_circular_tuple_windows_4(a: Vec<u8>) -> bool {
+ let x = (0..a.len()).map(|start_idx| (
+ &a[start_idx],
+ &a[(start_idx + 1) % a.len()],
+ &a[(start_idx + 2) % a.len()],
+ &a[(start_idx + 3) % a.len()],
+ ));
+ let y = a.iter().circular_tuple_windows::<(_, _, _, _)>();
+ itertools::assert_equal(x,y);
+ true
+ }
+
+ fn equal_cloned_circular_tuple_windows(a: Vec<u8>) -> bool {
+ let x = a.iter().circular_tuple_windows::<(_, _, _, _)>();
+ let y = x.clone();
+ itertools::assert_equal(x,y);
+ true
+ }
+
+ fn equal_cloned_circular_tuple_windows_noninitial(a: Vec<u8>) -> bool {
+ let mut x = a.iter().circular_tuple_windows::<(_, _, _, _)>();
+ let _ = x.next();
+ let y = x.clone();
+ itertools::assert_equal(x,y);
+ true
+ }
+
+ fn equal_cloned_circular_tuple_windows_complete(a: Vec<u8>) -> bool {
+ let mut x = a.iter().circular_tuple_windows::<(_, _, _, _)>();
+ for _ in x.by_ref() {}
+ let y = x.clone();
+ itertools::assert_equal(x,y);
+ true
+ }
+
fn equal_tuple_windows_1(a: Vec<u8>) -> bool {
let x = a.windows(1).map(|s| (&s[0], ));
let y = a.iter().tuple_windows::<(_,)>();
diff --git a/vendor/itertools/tests/test_std.rs b/vendor/itertools/tests/test_std.rs
index f59034234..77207d87e 100644
--- a/vendor/itertools/tests/test_std.rs
+++ b/vendor/itertools/tests/test_std.rs
@@ -221,6 +221,22 @@ fn all_equal() {
}
#[test]
+fn all_equal_value() {
+ assert_eq!("".chars().all_equal_value(), Err(None));
+ assert_eq!("A".chars().all_equal_value(), Ok('A'));
+ assert_eq!("AABBCCC".chars().all_equal_value(), Err(Some(('A', 'B'))));
+ assert_eq!("AAAAAAA".chars().all_equal_value(), Ok('A'));
+ {
+ let mut it = [1,2,3].iter().copied();
+ let result = it.all_equal_value();
+ assert_eq!(result, Err(Some((1, 2))));
+ let remaining = it.next();
+ assert_eq!(remaining, Some(3));
+ assert!(it.next().is_none());
+ }
+}
+
+#[test]
fn all_unique() {
assert!("ABCDEFGH".chars().all_unique());
assert!(!"ABCDEFGA".chars().all_unique());
@@ -1160,9 +1176,9 @@ fn exactly_one_question_mark_return() -> Result<(), ExactlyOneError<std::slice::
#[test]
fn multiunzip() {
- let (a, b, c): (Vec<_>, Vec<_>, Vec<_>) = [(0, 1, 2), (3, 4, 5), (6, 7, 8)].iter().cloned().multiunzip();
+ let (a, b, c): (Vec<_>, Vec<_>, Vec<_>) = [(0, 1, 2), (3, 4, 5), (6, 7, 8)].iter().cloned().multiunzip();
assert_eq!((a, b, c), (vec![0, 3, 6], vec![1, 4, 7], vec![2, 5, 8]));
let (): () = [(), (), ()].iter().cloned().multiunzip();
- let t: (Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>) = [(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)].iter().cloned().multiunzip();
+ let t: (Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>) = [(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)].iter().cloned().multiunzip();
assert_eq!(t, (vec![0], vec![1], vec![2], vec![3], vec![4], vec![5], vec![6], vec![7], vec![8], vec![9], vec![10], vec![11]));
}