Skip to content

Commit

Permalink
add test for vec::IntoIter::next_chunk() impl
Browse files Browse the repository at this point in the history
an adaption of the default impl's doctest
  • Loading branch information
the8472 committed Jul 26, 2022
1 parent 2f9f2e5 commit 4ba7cac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions library/alloc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
10 changes: 10 additions & 0 deletions library/alloc/tests/vec.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<I: Iterator<Item = i32>>(it: I, slice: &[i32]) {
Expand Down

0 comments on commit 4ba7cac

Please sign in to comment.