Skip to content

Commit

Permalink
Add tests for reaching the end of RangeInclusive as an iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Jul 8, 2017
1 parent 7a40307 commit e9a61ee
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/libcore/tests/iter.rs
Expand Up @@ -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));
Expand Down

0 comments on commit e9a61ee

Please sign in to comment.