Add tests for reaching the end of RangeInclusive as an iterator

This commit is contained in:
Simon Sapin 2017-07-06 18:13:44 +02:00
parent 7a40307a7c
commit e9a61eeb04

View File

@ -1076,6 +1076,26 @@ fn test_range() {
(isize::MAX as usize + 2, Some(isize::MAX as usize + 2)));
}
#[test]
fn test_range_inclusive_exhaustion() {
let mut r = 10...10;
assert_eq!(r.next(), Some(10));
assert_eq!(r, 1...0);
let mut r = 10...10;
assert_eq!(r.next_back(), Some(10));
assert_eq!(r, 1...0);
let mut r = 10...12;
assert_eq!(r.nth(2), Some(12));
assert_eq!(r, 1...0);
let mut r = 10...12;
assert_eq!(r.nth(5), None);
assert_eq!(r, 1...0);
}
#[test]
fn test_range_nth() {
assert_eq!((10..15).nth(0), Some(10));