about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexis Bourget <alexis.bourget@gmail.com>2020-09-08 23:04:03 +0200
committerAlexis Bourget <alexis.bourget@gmail.com>2020-09-21 21:50:26 +0200
commitfc152cd67e0b6d3f11f49eae43183d03a3b8bf17 (patch)
tree0cc15530c2511b46e5ef05df9c1a959040f786ca
parentaf44a2a857618150b180dabe9c3383a3911b3640 (diff)
downloadrust-fc152cd67e0b6d3f11f49eae43183d03a3b8bf17.tar.gz
rust-fc152cd67e0b6d3f11f49eae43183d03a3b8bf17.zip
move 'test zip ...' tests
-rw-r--r--library/core/tests/iter.rs95
-rw-r--r--src/test/ui/iterators/iter-zip.rs103
2 files changed, 95 insertions, 103 deletions
diff --git a/library/core/tests/iter.rs b/library/core/tests/iter.rs
index 0eb9af3f454..6680205c26c 100644
--- a/library/core/tests/iter.rs
+++ b/library/core/tests/iter.rs
@@ -376,6 +376,101 @@ fn test_zip_next_back_side_effects_exhausted() {
     assert_eq!(b, vec![200, 300, 400]);
 }
 
+#[derive(Debug)]
+struct CountClone(Cell<i32>);
+
+fn count_clone() -> CountClone { CountClone(Cell::new(0)) }
+
+impl PartialEq<i32> for CountClone {
+    fn eq(&self, rhs: &i32) -> bool {
+        self.0.get() == *rhs
+    }
+}
+
+impl Clone for CountClone {
+    fn clone(&self) -> Self {
+        let ret = CountClone(self.0.clone());
+        let n = self.0.get();
+        self.0.set(n + 1);
+        ret
+    }
+}
+
+#[test]
+fn test_zip_cloned_sideffectful() {
+    let xs = [count_clone(), count_clone(), count_clone(), count_clone()];
+    let ys = [count_clone(), count_clone()];
+
+    for _ in xs.iter().cloned().zip(ys.iter().cloned()) { }
+
+    assert_eq!(&xs, &[1, 1, 1, 0][..]);
+    assert_eq!(&ys, &[1, 1][..]);
+
+    let xs = [count_clone(), count_clone()];
+    let ys = [count_clone(), count_clone(), count_clone(), count_clone()];
+
+    for _ in xs.iter().cloned().zip(ys.iter().cloned()) { }
+
+    assert_eq!(&xs, &[1, 1][..]);
+    assert_eq!(&ys, &[1, 1, 0, 0][..]);
+}
+
+#[test]
+fn test_zip_map_sideffectful() {
+    let mut xs = [0; 6];
+    let mut ys = [0; 4];
+
+    for _ in xs.iter_mut().map(|x| *x += 1).zip(ys.iter_mut().map(|y| *y += 1)) { }
+
+    assert_eq!(&xs, &[1, 1, 1, 1, 1, 0]);
+    assert_eq!(&ys, &[1, 1, 1, 1]);
+
+    let mut xs = [0; 4];
+    let mut ys = [0; 6];
+
+    for _ in xs.iter_mut().map(|x| *x += 1).zip(ys.iter_mut().map(|y| *y += 1)) { }
+
+    assert_eq!(&xs, &[1, 1, 1, 1]);
+    assert_eq!(&ys, &[1, 1, 1, 1, 0, 0]);
+}
+
+#[test]
+fn test_zip_map_rev_sideffectful() {
+    let mut xs = [0; 6];
+    let mut ys = [0; 4];
+
+    {
+        let mut it = xs.iter_mut().map(|x| *x += 1).zip(ys.iter_mut().map(|y| *y += 1));
+        it.next_back();
+    }
+    assert_eq!(&xs, &[0, 0, 0, 1, 1, 1]);
+    assert_eq!(&ys, &[0, 0, 0, 1]);
+
+    let mut xs = [0; 6];
+    let mut ys = [0; 4];
+
+    {
+        let mut it = xs.iter_mut().map(|x| *x += 1).zip(ys.iter_mut().map(|y| *y += 1));
+        (&mut it).take(5).count();
+        it.next_back();
+    }
+    assert_eq!(&xs, &[1, 1, 1, 1, 1, 1]);
+    assert_eq!(&ys, &[1, 1, 1, 1]);
+}
+
+#[test]
+fn test_zip_nested_sideffectful() {
+    let mut xs = [0; 6];
+    let ys = [0; 4];
+
+    {
+        // test that it has the side effect nested inside enumerate
+        let it = xs.iter_mut().map(|x| *x = 1).enumerate().zip(&ys);
+        it.count();
+    }
+    assert_eq!(&xs, &[1, 1, 1, 1, 1, 0]);
+}
+
 #[test]
 fn test_zip_nth_back_side_effects_exhausted() {
     let mut a = Vec::new();
diff --git a/src/test/ui/iterators/iter-zip.rs b/src/test/ui/iterators/iter-zip.rs
deleted file mode 100644
index a76fa2408bb..00000000000
--- a/src/test/ui/iterators/iter-zip.rs
+++ /dev/null
@@ -1,103 +0,0 @@
-// run-pass
-// Test that .zip() specialization preserves side effects
-// in sideeffectful iterator adaptors.
-
-use std::cell::Cell;
-
-#[derive(Debug)]
-struct CountClone(Cell<i32>);
-
-fn count_clone() -> CountClone { CountClone(Cell::new(0)) }
-
-impl PartialEq<i32> for CountClone {
-    fn eq(&self, rhs: &i32) -> bool {
-        self.0.get() == *rhs
-    }
-}
-
-impl Clone for CountClone {
-    fn clone(&self) -> Self {
-        let ret = CountClone(self.0.clone());
-        let n = self.0.get();
-        self.0.set(n + 1);
-        ret
-    }
-}
-
-fn test_zip_cloned_sideffectful() {
-    let xs = [count_clone(), count_clone(), count_clone(), count_clone()];
-    let ys = [count_clone(), count_clone()];
-
-    for _ in xs.iter().cloned().zip(ys.iter().cloned()) { }
-
-    assert_eq!(&xs, &[1, 1, 1, 0][..]);
-    assert_eq!(&ys, &[1, 1][..]);
-
-    let xs = [count_clone(), count_clone()];
-    let ys = [count_clone(), count_clone(), count_clone(), count_clone()];
-
-    for _ in xs.iter().cloned().zip(ys.iter().cloned()) { }
-
-    assert_eq!(&xs, &[1, 1][..]);
-    assert_eq!(&ys, &[1, 1, 0, 0][..]);
-}
-
-fn test_zip_map_sideffectful() {
-    let mut xs = [0; 6];
-    let mut ys = [0; 4];
-
-    for _ in xs.iter_mut().map(|x| *x += 1).zip(ys.iter_mut().map(|y| *y += 1)) { }
-
-    assert_eq!(&xs, &[1, 1, 1, 1, 1, 0]);
-    assert_eq!(&ys, &[1, 1, 1, 1]);
-
-    let mut xs = [0; 4];
-    let mut ys = [0; 6];
-
-    for _ in xs.iter_mut().map(|x| *x += 1).zip(ys.iter_mut().map(|y| *y += 1)) { }
-
-    assert_eq!(&xs, &[1, 1, 1, 1]);
-    assert_eq!(&ys, &[1, 1, 1, 1, 0, 0]);
-}
-
-fn test_zip_map_rev_sideffectful() {
-    let mut xs = [0; 6];
-    let mut ys = [0; 4];
-
-    {
-        let mut it = xs.iter_mut().map(|x| *x += 1).zip(ys.iter_mut().map(|y| *y += 1));
-        it.next_back();
-    }
-    assert_eq!(&xs, &[0, 0, 0, 1, 1, 1]);
-    assert_eq!(&ys, &[0, 0, 0, 1]);
-
-    let mut xs = [0; 6];
-    let mut ys = [0; 4];
-
-    {
-        let mut it = xs.iter_mut().map(|x| *x += 1).zip(ys.iter_mut().map(|y| *y += 1));
-        (&mut it).take(5).count();
-        it.next_back();
-    }
-    assert_eq!(&xs, &[1, 1, 1, 1, 1, 1]);
-    assert_eq!(&ys, &[1, 1, 1, 1]);
-}
-
-fn test_zip_nested_sideffectful() {
-    let mut xs = [0; 6];
-    let ys = [0; 4];
-
-    {
-        // test that it has the side effect nested inside enumerate
-        let it = xs.iter_mut().map(|x| *x = 1).enumerate().zip(&ys);
-        it.count();
-    }
-    assert_eq!(&xs, &[1, 1, 1, 1, 1, 0]);
-}
-
-fn main() {
-    test_zip_cloned_sideffectful();
-    test_zip_map_sideffectful();
-    test_zip_map_rev_sideffectful();
-    test_zip_nested_sideffectful();
-}