about summary refs log tree commit diff
path: root/src/libcore/tests
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-04-19 06:03:12 +0200
committerGitHub <noreply@github.com>2019-04-19 06:03:12 +0200
commit291e44b3815b95b02bba0bf873351a2b6dfd72b9 (patch)
treee0e7a8c70f5cfdbf4e0861c44f5c91ad67cc9fd7 /src/libcore/tests
parent7f450bd3ca9edd39b876293650d49dc17d200256 (diff)
parent2605537012022980d5ec69ad11653794db935cf6 (diff)
downloadrust-291e44b3815b95b02bba0bf873351a2b6dfd72b9.tar.gz
rust-291e44b3815b95b02bba0bf873351a2b6dfd72b9.zip
Rollup merge of #60023 - koalatux:nth-back, r=scottmcm
implement specialized nth_back() for Bytes, Fuse and Enumerate

Hi,

After my first PR has been successfully merged, here is my second pull request :-)

Also this PR contains some specializations for the problem discussed in #54054.
Diffstat (limited to 'src/libcore/tests')
-rw-r--r--src/libcore/tests/iter.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs
index d5b581d336d..5247331fba2 100644
--- a/src/libcore/tests/iter.rs
+++ b/src/libcore/tests/iter.rs
@@ -390,6 +390,24 @@ fn test_iterator_enumerate_nth() {
 }
 
 #[test]
+fn test_iterator_enumerate_nth_back() {
+    let xs = [0, 1, 2, 3, 4, 5];
+    let mut it = xs.iter().enumerate();
+    while let Some((i, &x)) = it.nth_back(0) {
+        assert_eq!(i, x);
+    }
+
+    let mut it = xs.iter().enumerate();
+    while let Some((i, &x)) = it.nth_back(1) {
+        assert_eq!(i, x);
+    }
+
+    let (i, &x) = xs.iter().enumerate().nth_back(3).unwrap();
+    assert_eq!(i, x);
+    assert_eq!(i, 2);
+}
+
+#[test]
 fn test_iterator_enumerate_count() {
     let xs = [0, 1, 2, 3, 4, 5];
     assert_eq!(xs.iter().enumerate().count(), 6);