mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Add tests for Range*::nth
This commit is contained in:
parent
de4afc6797
commit
7a40307a7c
@ -1076,6 +1076,55 @@ fn test_range() {
|
||||
(isize::MAX as usize + 2, Some(isize::MAX as usize + 2)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_nth() {
|
||||
assert_eq!((10..15).nth(0), Some(10));
|
||||
assert_eq!((10..15).nth(1), Some(11));
|
||||
assert_eq!((10..15).nth(4), Some(14));
|
||||
assert_eq!((10..15).nth(5), None);
|
||||
|
||||
let mut r = 10..20;
|
||||
assert_eq!(r.nth(2), Some(12));
|
||||
assert_eq!(r, 13..20);
|
||||
assert_eq!(r.nth(2), Some(15));
|
||||
assert_eq!(r, 16..20);
|
||||
assert_eq!(r.nth(10), None);
|
||||
assert_eq!(r, 20..20);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_from_nth() {
|
||||
assert_eq!((10..).nth(0), Some(10));
|
||||
assert_eq!((10..).nth(1), Some(11));
|
||||
assert_eq!((10..).nth(4), Some(14));
|
||||
|
||||
let mut r = 10..;
|
||||
assert_eq!(r.nth(2), Some(12));
|
||||
assert_eq!(r, 13..);
|
||||
assert_eq!(r.nth(2), Some(15));
|
||||
assert_eq!(r, 16..);
|
||||
assert_eq!(r.nth(10), Some(26));
|
||||
assert_eq!(r, 27..);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_inclusive_nth() {
|
||||
assert_eq!((10...15).nth(0), Some(10));
|
||||
assert_eq!((10...15).nth(1), Some(11));
|
||||
assert_eq!((10...15).nth(5), Some(15));
|
||||
assert_eq!((10...15).nth(6), None);
|
||||
|
||||
let mut r = 10_u8...20;
|
||||
assert_eq!(r.nth(2), Some(12));
|
||||
assert_eq!(r, 13...20);
|
||||
assert_eq!(r.nth(2), Some(15));
|
||||
assert_eq!(r, 16...20);
|
||||
assert_eq!(r.is_empty(), false);
|
||||
assert_eq!(r.nth(10), None);
|
||||
assert_eq!(r.is_empty(), true);
|
||||
assert_eq!(r, 1...0); // We may not want to document/promise this detail
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_step() {
|
||||
#![allow(deprecated)]
|
||||
|
@ -18,12 +18,14 @@
|
||||
#![feature(core_private_diy_float)]
|
||||
#![feature(dec2flt)]
|
||||
#![feature(decode_utf8)]
|
||||
#![feature(exact_size_is_empty)]
|
||||
#![feature(fixed_size_array)]
|
||||
#![feature(flt2dec)]
|
||||
#![feature(fmt_internals)]
|
||||
#![feature(iterator_step_by)]
|
||||
#![feature(i128_type)]
|
||||
#![feature(inclusive_range)]
|
||||
#![feature(inclusive_range_syntax)]
|
||||
#![feature(iter_rfind)]
|
||||
#![feature(libc)]
|
||||
#![feature(nonzero)]
|
||||
|
Loading…
Reference in New Issue
Block a user