diff options
| author | Josh Stone <jistone@redhat.com> | 2017-09-15 10:30:56 -0700 |
|---|---|---|
| committer | Josh Stone <jistone@redhat.com> | 2017-09-15 10:30:56 -0700 |
| commit | 351f56a6034486c38c3b36bfbbd15a81a39ba9aa (patch) | |
| tree | ba1496b4df03f0f636554848de8057553e1a196f | |
| parent | 61a7703e5575795e837d16d3a0ec46551cc6b69b (diff) | |
| download | rust-351f56a6034486c38c3b36bfbbd15a81a39ba9aa.tar.gz rust-351f56a6034486c38c3b36bfbbd15a81a39ba9aa.zip | |
Add a specific test for `FlatMap::fold`
| -rw-r--r-- | src/libcore/tests/iter.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs index ed6923929d6..59ae30de452 100644 --- a/src/libcore/tests/iter.rs +++ b/src/libcore/tests/iter.rs @@ -654,6 +654,22 @@ fn test_iterator_flat_map() { assert_eq!(i, ys.len()); } +/// Test `FlatMap::fold` with items already picked off the front and back, +/// to make sure all parts of the `FlatMap` are folded correctly. +#[test] +fn test_iterator_flat_map_fold() { + let xs = [0, 3, 6]; + let ys = [1, 2, 3, 4, 5, 6, 7]; + let mut it = xs.iter().flat_map(|&x| x..x+3); + it.next(); + it.next_back(); + let i = it.fold(0, |i, x| { + assert_eq!(x, ys[i]); + i + 1 + }); + assert_eq!(i, ys.len()); +} + #[test] fn test_inspect() { let xs = [1, 2, 3, 4]; |
