about summary refs log tree commit diff
path: root/src/libcore/tests
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2017-07-06 17:13:29 +0200
committerSimon Sapin <simon.sapin@exyr.org>2017-07-08 08:55:55 +0200
commit7a40307a7ca44d8ff4035c59022647cddc5b6699 (patch)
treec426035ac103e0a107c3baac6a439e3a2406ee48 /src/libcore/tests
parentde4afc6797a7a3b4973cbcb897e25a3a0213516b (diff)
downloadrust-7a40307a7ca44d8ff4035c59022647cddc5b6699.tar.gz
rust-7a40307a7ca44d8ff4035c59022647cddc5b6699.zip
Add tests for Range*::nth
Diffstat (limited to 'src/libcore/tests')
-rw-r--r--src/libcore/tests/iter.rs49
-rw-r--r--src/libcore/tests/lib.rs2
2 files changed, 51 insertions, 0 deletions
diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs
index 14f0260f571..748eac10ac0 100644
--- a/src/libcore/tests/iter.rs
+++ b/src/libcore/tests/iter.rs
@@ -1077,6 +1077,55 @@ fn test_range() {
 }
 
 #[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)]
 
diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs
index 8d3e367d237..26e4c21dc8f 100644
--- a/src/libcore/tests/lib.rs
+++ b/src/libcore/tests/lib.rs
@@ -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)]