Skip to content

Commit 4ba7cac

Browse files
committed
add test for vec::IntoIter::next_chunk() impl
an adaption of the default impl's doctest
1 parent 2f9f2e5 commit 4ba7cac

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

library/alloc/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#![feature(binary_heap_as_slice)]
3030
#![feature(inplace_iteration)]
3131
#![feature(iter_advance_by)]
32+
#![feature(iter_next_chunk)]
3233
#![feature(round_char_boundary)]
3334
#![feature(slice_group_by)]
3435
#![feature(slice_partition_dedup)]

library/alloc/tests/vec.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use core::alloc::{Allocator, Layout};
2+
use core::iter::IntoIterator;
23
use core::ptr::NonNull;
34
use std::alloc::System;
45
use std::assert_matches::assert_matches;
@@ -930,6 +931,15 @@ fn test_into_iter_count() {
930931
assert_eq!([1, 2, 3].into_iter().count(), 3);
931932
}
932933

934+
#[test]
935+
fn test_into_iter_next_chunk() {
936+
let mut iter = b"lorem".to_vec().into_iter();
937+
938+
assert_eq!(iter.next_chunk().unwrap(), [b'l', b'o']); // N is inferred as 2
939+
assert_eq!(iter.next_chunk().unwrap(), [b'r', b'e', b'm']); // N is inferred as 3
940+
assert_eq!(iter.next_chunk::<4>().unwrap_err().as_slice(), &[]); // N is explicitly 4
941+
}
942+
933943
#[test]
934944
fn test_into_iter_clone() {
935945
fn iter_equal<I: Iterator<Item = i32>>(it: I, slice: &[i32]) {

0 commit comments

Comments
 (0)