diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-20 08:35:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-20 08:35:58 +0200 |
| commit | 3e08f1b57ea6df87ee2d01f31339958998f8ea26 (patch) | |
| tree | 59ff79d60280f87ec16e094fa01bcc36f2ecbb43 /src/libcore/tests | |
| parent | 3c805ce183840bd20bd81a54a02b3c8b6dccc9dd (diff) | |
| parent | e80a37558df5ac9828caccd48459fdb7be488f5b (diff) | |
| download | rust-3e08f1b57ea6df87ee2d01f31339958998f8ea26.tar.gz rust-3e08f1b57ea6df87ee2d01f31339958998f8ea26.zip | |
Rollup merge of #60454 - acrrd:issues/54054_skip, r=scottmcm
Add custom nth_back to Skip Implementation of nth_back for Skip. Part of #54054
Diffstat (limited to 'src/libcore/tests')
| -rw-r--r-- | src/libcore/tests/iter.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs index 020618ae7ae..4d840ef24c8 100644 --- a/src/libcore/tests/iter.rs +++ b/src/libcore/tests/iter.rs @@ -2334,6 +2334,40 @@ fn test_skip_try_folds() { } #[test] +fn test_skip_nth_back() { + let xs = [0, 1, 2, 3, 4, 5]; + let mut it = xs.iter().skip(2); + assert_eq!(it.nth_back(0), Some(&5)); + assert_eq!(it.nth_back(1), Some(&3)); + assert_eq!(it.nth_back(0), Some(&2)); + assert_eq!(it.nth_back(0), None); + + let ys = [2, 3, 4, 5]; + let mut ity = ys.iter(); + let mut it = xs.iter().skip(2); + assert_eq!(it.nth_back(1), ity.nth_back(1)); + assert_eq!(it.clone().nth(0), ity.clone().nth(0)); + assert_eq!(it.nth_back(0), ity.nth_back(0)); + assert_eq!(it.clone().nth(0), ity.clone().nth(0)); + assert_eq!(it.nth_back(0), ity.nth_back(0)); + assert_eq!(it.clone().nth(0), ity.clone().nth(0)); + assert_eq!(it.nth_back(0), ity.nth_back(0)); + assert_eq!(it.clone().nth(0), ity.clone().nth(0)); + + let mut it = xs.iter().skip(2); + assert_eq!(it.nth_back(4), None); + assert_eq!(it.nth_back(0), None); + + let mut it = xs.iter(); + it.by_ref().skip(2).nth_back(3); + assert_eq!(it.next_back(), Some(&1)); + + let mut it = xs.iter(); + it.by_ref().skip(2).nth_back(10); + assert_eq!(it.next_back(), Some(&1)); +} + +#[test] fn test_take_try_folds() { let f = &|acc, x| i32::checked_add(2*acc, x); assert_eq!((10..30).take(10).try_fold(7, f), (10..20).try_fold(7, f)); |
