about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2018-07-19 12:28:43 +0200
committerRalf Jung <post@ralfj.de>2018-08-02 00:33:03 +0200
commit60b06369eea523b9d8fe606357177f126bef4b42 (patch)
tree03f06b7439fb9874aaceacc4836a4fb93ca9e48d
parentcbdba2b4c25ef884e05587b0fc2e4b21e0d302cb (diff)
downloadrust-60b06369eea523b9d8fe606357177f126bef4b42.tar.gz
rust-60b06369eea523b9d8fe606357177f126bef4b42.zip
test nth better
-rw-r--r--src/libcore/tests/slice.rs48
1 files changed, 37 insertions, 11 deletions
diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs
index e4230b08497..7968521f7b4 100644
--- a/src/libcore/tests/slice.rs
+++ b/src/libcore/tests/slice.rs
@@ -395,7 +395,7 @@ fn test_windows_zip() {
 fn test_iter_ref_consistency() {
     use std::fmt::Debug;
 
-    fn helper<T : Copy + Debug + PartialEq>(x : T) {
+    fn test<T : Copy + Debug + PartialEq>(x : T) {
         let v : &[T] = &[x, x, x];
         let v_ptrs : [*const T; 3] = match v {
             [ref v1, ref v2, ref v3] => [v1 as *const _, v2 as *const _, v3 as *const _],
@@ -403,6 +403,7 @@ fn test_iter_ref_consistency() {
         };
         let len = v.len();
 
+        // nth(i)
         for i in 0..len {
             assert_eq!(&v[i] as *const _, v_ptrs[i]); // check the v_ptrs array, just to be sure
             let nth = v.iter().nth(i).unwrap();
@@ -410,9 +411,20 @@ fn test_iter_ref_consistency() {
         }
         assert_eq!(v.iter().nth(len), None, "nth(len) should return None");
 
+        // stepping through with nth(0)
         {
             let mut it = v.iter();
-            for i in 0..len{
+            for i in 0..len {
+                let next = it.nth(0).unwrap();
+                assert_eq!(next as *const _, v_ptrs[i]);
+            }
+            assert_eq!(it.nth(0), None);
+        }
+
+        // next()
+        {
+            let mut it = v.iter();
+            for i in 0..len {
                 let remaining = len - i;
                 assert_eq!(it.size_hint(), (remaining, Some(remaining)));
 
@@ -423,9 +435,10 @@ fn test_iter_ref_consistency() {
             assert_eq!(it.next(), None, "The final call to next() should return None");
         }
 
+        // next_back()
         {
             let mut it = v.iter();
-            for i in 0..len{
+            for i in 0..len {
                 let remaining = len - i;
                 assert_eq!(it.size_hint(), (remaining, Some(remaining)));
 
@@ -437,7 +450,7 @@ fn test_iter_ref_consistency() {
         }
     }
 
-    fn helper_mut<T : Copy + Debug + PartialEq>(x : T) {
+    fn test_mut<T : Copy + Debug + PartialEq>(x : T) {
         let v : &mut [T] = &mut [x, x, x];
         let v_ptrs : [*mut T; 3] = match v {
             [ref v1, ref v2, ref v3] =>
@@ -446,6 +459,7 @@ fn test_iter_ref_consistency() {
         };
         let len = v.len();
 
+        // nth(i)
         for i in 0..len {
             assert_eq!(&mut v[i] as *mut _, v_ptrs[i]); // check the v_ptrs array, just to be sure
             let nth = v.iter_mut().nth(i).unwrap();
@@ -453,6 +467,17 @@ fn test_iter_ref_consistency() {
         }
         assert_eq!(v.iter().nth(len), None, "nth(len) should return None");
 
+        // stepping through with nth(0)
+        {
+            let mut it = v.iter();
+            for i in 0..len {
+                let next = it.nth(0).unwrap();
+                assert_eq!(next as *const _, v_ptrs[i]);
+            }
+            assert_eq!(it.nth(0), None);
+        }
+
+        // next()
         {
             let mut it = v.iter_mut();
             for i in 0..len {
@@ -466,9 +491,10 @@ fn test_iter_ref_consistency() {
             assert_eq!(it.next(), None, "The final call to next() should return None");
         }
 
+        // next_back()
         {
             let mut it = v.iter_mut();
-            for i in 0..len{
+            for i in 0..len {
                 let remaining = len - i;
                 assert_eq!(it.size_hint(), (remaining, Some(remaining)));
 
@@ -482,12 +508,12 @@ fn test_iter_ref_consistency() {
 
     // Make sure iterators and slice patterns yield consistent addresses for various types,
     // including ZSTs.
-    helper(0u32);
-    helper(());
-    helper([0u32; 0]); // ZST with alignment > 0
-    helper_mut(0u32);
-    helper_mut(());
-    helper_mut([0u32; 0]); // ZST with alignment > 0
+    test(0u32);
+    test(());
+    test([0u32; 0]); // ZST with alignment > 0
+    test_mut(0u32);
+    test_mut(());
+    test_mut([0u32; 0]); // ZST with alignment > 0
 }
 
 // The current implementation of SliceIndex fails to handle methods