From 4ba7cac359b0180add75d78929ebae4f90813fa1 Mon Sep 17 00:00:00 2001 From: The 8472 Date: Tue, 26 Jul 2022 21:28:14 +0200 Subject: [PATCH] add test for vec::IntoIter::next_chunk() impl an adaption of the default impl's doctest --- library/alloc/tests/lib.rs | 1 + library/alloc/tests/vec.rs | 10 ++++++++++ 2 files changed, 11 insertions(+) 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; @@ -930,6 +931,15 @@ fn test_into_iter_count() { assert_eq!([1, 2, 3].into_iter().count(), 3); } +#[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>(it: I, slice: &[i32]) {