about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorblake2-ppc <blake2-ppc>2013-09-01 16:43:47 +0200
committerblake2-ppc <blake2-ppc>2013-09-01 18:17:19 +0200
commit04845f0aebd6928bb924147fd93de8dac13ff850 (patch)
treea823cc9a1bb7092046d52775ed4fefd35720b380 /src/libstd
parent43ef5ad18410da5f50efc78fbb781f4e1037b02a (diff)
downloadrust-04845f0aebd6928bb924147fd93de8dac13ff850.tar.gz
rust-04845f0aebd6928bb924147fd93de8dac13ff850.zip
std::iterator: Add back .rposition() test
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/iterator.rs25
-rw-r--r--src/libstd/vec.rs10
2 files changed, 25 insertions, 10 deletions
diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs
index d1b59c30978..77e51e01c0c 100644
--- a/src/libstd/iterator.rs
+++ b/src/libstd/iterator.rs
@@ -2367,6 +2367,31 @@ mod tests {
         assert_eq!(it.next_back(), None)
     }
 
+    #[test]
+    fn test_rposition() {
+        fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' }
+        fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' }
+        let v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
+
+        assert_eq!(v.iter().rposition(f), Some(3u));
+        assert!(v.iter().rposition(g).is_none());
+    }
+
+    #[test]
+    #[should_fail]
+    fn test_rposition_fail() {
+        let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
+        let mut i = 0;
+        do v.iter().rposition |_elt| {
+            if i == 2 {
+                fail!()
+            }
+            i += 1;
+            false
+        };
+    }
+
+
     #[cfg(test)]
     fn check_randacc_iter<A: Eq, T: Clone + RandomAccessIterator<A>>(a: T, len: uint)
     {
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 39560bd47e6..f8aaf653645 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -2911,16 +2911,6 @@ mod tests {
     }
 
     #[test]
-    fn test_rposition() {
-        fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' }
-        fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' }
-        let v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
-
-        assert_eq!(v.iter().rposition(f), Some(3u));
-        assert!(v.iter().rposition(g).is_none());
-    }
-
-    #[test]
     fn test_bsearch_elem() {
         assert_eq!([1,2,3,4,5].bsearch_elem(&5), Some(4));
         assert_eq!([1,2,3,4,5].bsearch_elem(&4), Some(3));