about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThe 8472 <git@infinite-source.de>2022-07-26 21:28:14 +0200
committerThe 8472 <git@infinite-source.de>2022-07-26 21:43:25 +0200
commit4ba7cac359b0180add75d78929ebae4f90813fa1 (patch)
treee95cd9446b28ac737ab9a8bab4d022673aff2f6c
parent2f9f2e507eaecf45074727e34af02642b95fa724 (diff)
downloadrust-4ba7cac359b0180add75d78929ebae4f90813fa1.tar.gz
rust-4ba7cac359b0180add75d78929ebae4f90813fa1.zip
add test for vec::IntoIter::next_chunk() impl
an adaption of the default impl's doctest
-rw-r--r--library/alloc/tests/lib.rs1
-rw-r--r--library/alloc/tests/vec.rs10
2 files changed, 11 insertions, 0 deletions
diff --git a/library/alloc/tests/lib.rs b/library/alloc/tests/lib.rs
index 367cdcdcc06..d40778121c2 100644
--- a/library/alloc/tests/lib.rs
+++ b/library/alloc/tests/lib.rs
@@ -29,6 +29,7 @@
 #![feature(binary_heap_as_slice)]
 #![feature(inplace_iteration)]
 #![feature(iter_advance_by)]
+#![feature(iter_next_chunk)]
 #![feature(round_char_boundary)]
 #![feature(slice_group_by)]
 #![feature(slice_partition_dedup)]
diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs
index 5520f6ebf19..b797e237535 100644
--- a/library/alloc/tests/vec.rs
+++ b/library/alloc/tests/vec.rs
@@ -1,4 +1,5 @@
 use core::alloc::{Allocator, Layout};
+use core::iter::IntoIterator;
 use core::ptr::NonNull;
 use std::alloc::System;
 use std::assert_matches::assert_matches;
@@ -931,6 +932,15 @@ fn test_into_iter_count() {
 }
 
 #[test]
+fn test_into_iter_next_chunk() {
+    let mut iter = b"lorem".to_vec().into_iter();
+
+    assert_eq!(iter.next_chunk().unwrap(), [b'l', b'o']); // N is inferred as 2
+    assert_eq!(iter.next_chunk().unwrap(), [b'r', b'e', b'm']); // N is inferred as 3
+    assert_eq!(iter.next_chunk::<4>().unwrap_err().as_slice(), &[]); // N is explicitly 4
+}
+
+#[test]
 fn test_into_iter_clone() {
     fn iter_equal<I: Iterator<Item = i32>>(it: I, slice: &[i32]) {
         let v: Vec<i32> = it.collect();