about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2017-09-15 10:30:56 -0700
committerJosh Stone <jistone@redhat.com>2017-09-15 10:30:56 -0700
commit351f56a6034486c38c3b36bfbbd15a81a39ba9aa (patch)
treeba1496b4df03f0f636554848de8057553e1a196f
parent61a7703e5575795e837d16d3a0ec46551cc6b69b (diff)
downloadrust-351f56a6034486c38c3b36bfbbd15a81a39ba9aa.tar.gz
rust-351f56a6034486c38c3b36bfbbd15a81a39ba9aa.zip
Add a specific test for `FlatMap::fold`
-rw-r--r--src/libcore/tests/iter.rs16
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];