about summary refs log tree commit diff
path: root/src/libcore/tests
diff options
context:
space:
mode:
authorClar Fon <them@lightdark.xyz>2018-12-13 23:26:09 -0500
committerClar Fon <them@lightdark.xyz>2018-12-20 01:18:04 -0500
commitfb18ddaaaa8eeec29bf6fc8684cfceccaa09e064 (patch)
tree19383c12741f33b907d84de87f42f8ef0e0fbd7a /src/libcore/tests
parent0a4a4ffc69f2d05eb8b8a32eaf9bd0607b69fe38 (diff)
downloadrust-fb18ddaaaa8eeec29bf6fc8684cfceccaa09e064.tar.gz
rust-fb18ddaaaa8eeec29bf6fc8684cfceccaa09e064.zip
Add DoubleEndedIterator::nth_back
Diffstat (limited to 'src/libcore/tests')
-rw-r--r--src/libcore/tests/iter.rs27
-rw-r--r--src/libcore/tests/lib.rs1
2 files changed, 28 insertions, 0 deletions
diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs
index 00b4aa4fa2d..b5633333d01 100644
--- a/src/libcore/tests/iter.rs
+++ b/src/libcore/tests/iter.rs
@@ -1017,6 +1017,33 @@ fn test_iterator_nth() {
 }
 
 #[test]
+fn test_iterator_nth_back() {
+    let v: &[_] = &[0, 1, 2, 3, 4];
+    for i in 0..v.len() {
+        assert_eq!(v.iter().nth_back(i).unwrap(), &v[v.len() - 1 - i]);
+    }
+    assert_eq!(v.iter().nth_back(v.len()), None);
+}
+
+#[test]
+fn test_iterator_rev_nth_back() {
+    let v: &[_] = &[0, 1, 2, 3, 4];
+    for i in 0..v.len() {
+        assert_eq!(v.iter().rev().nth_back(i).unwrap(), &v[i]);
+    }
+    assert_eq!(v.iter().rev().nth_back(v.len()), None);
+}
+
+#[test]
+fn test_iterator_rev_nth() {
+    let v: &[_] = &[0, 1, 2, 3, 4];
+    for i in 0..v.len() {
+        assert_eq!(v.iter().rev().nth(i).unwrap(), &v[v.len() - 1 - i]);
+    }
+    assert_eq!(v.iter().rev().nth(v.len()), None);
+}
+
+#[test]
 fn test_iterator_last() {
     let v: &[_] = &[0, 1, 2, 3, 4];
     assert_eq!(v.iter().last().unwrap(), &4);
diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs
index 7d62b4fa90f..2377a473367 100644
--- a/src/libcore/tests/lib.rs
+++ b/src/libcore/tests/lib.rs
@@ -19,6 +19,7 @@
 #![feature(flt2dec)]
 #![feature(fmt_internals)]
 #![feature(hashmap_internals)]
+#![feature(iter_nth_back)]
 #![feature(iter_unfold)]
 #![feature(pattern)]
 #![feature(range_is_empty)]