Skip to content

Commit 351f56a

Browse files
committed
Add a specific test for FlatMap::fold
1 parent 61a7703 commit 351f56a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/libcore/tests/iter.rs

+16
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,22 @@ fn test_iterator_flat_map() {
654654
assert_eq!(i, ys.len());
655655
}
656656

657+
/// Test `FlatMap::fold` with items already picked off the front and back,
658+
/// to make sure all parts of the `FlatMap` are folded correctly.
659+
#[test]
660+
fn test_iterator_flat_map_fold() {
661+
let xs = [0, 3, 6];
662+
let ys = [1, 2, 3, 4, 5, 6, 7];
663+
let mut it = xs.iter().flat_map(|&x| x..x+3);
664+
it.next();
665+
it.next_back();
666+
let i = it.fold(0, |i, x| {
667+
assert_eq!(x, ys[i]);
668+
i + 1
669+
});
670+
assert_eq!(i, ys.len());
671+
}
672+
657673
#[test]
658674
fn test_inspect() {
659675
let xs = [1, 2, 3, 4];

0 commit comments

Comments
 (0)