Skip to content

Commit 255f285

Browse files
committed
add tests for array_chunks
1 parent eb594a2 commit 255f285

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/libcore/slice/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,6 @@ impl<T> [T] {
859859
/// ```
860860
///
861861
/// [`chunks`]: #method.chunks
862-
/// [`rchunks_exact`]: #method.rchunks_exact
863862
#[unstable(feature = "array_chunks", issue = "none")]
864863
#[inline]
865864
pub fn array_chunks<const N: usize>(&self) -> ArrayChunks<'_, T, N> {

src/libcore/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(alloc_layout_extra)]
2+
#![feature(array_chunks)]
23
#![feature(bool_to_option)]
34
#![feature(bound_cloned)]
45
#![feature(box_syntax)]

src/libcore/tests/slice.rs

+22
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,28 @@ fn test_chunks_exact_mut_zip() {
433433
assert_eq!(v1, [13, 14, 19, 20, 4]);
434434
}
435435

436+
// FIXME(#71154)
437+
// FIXME(const_generics)
438+
// We can't yet use `v.array_chunks::<3>()`, so until either #71154 or a
439+
// different PR implementing const arguments in type dependent paths lands,
440+
// we can't yet test many uses.
441+
#[test]
442+
fn test_array_chunks_simple() {
443+
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
444+
let mut c = <[i32]>::array_chunks(&v);
445+
assert!(matches!(c.next(), Some(&[0, 1, 2])));
446+
assert!(matches!(c.next(), Some(&[3, 4, 5])));
447+
assert!(matches!(c.next(), None));
448+
449+
let v2: &[i32] = &[0, 1, 2, 3, 4];
450+
let c2 = <[i32]>::array_chunks(&v2);
451+
for &[a, b, c] in c2 {
452+
assert_eq!(a, 0i32);
453+
assert_eq!(b, 1i32);
454+
assert_eq!(c, 2i32);
455+
}
456+
}
457+
436458
#[test]
437459
fn test_rchunks_count() {
438460
let v: &[i32] = &[0, 1, 2, 3, 4, 5];

0 commit comments

Comments
 (0)