1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use core::ops::{Range, RangeFull, RangeFrom, RangeTo, RangeInclusive};
13 // Test the Range structs without the syntactic sugar.
17 let r = Range { start: 2, end: 10 };
19 for (i, ri) in r.enumerate() {
21 assert!(ri >= 2 && ri < 10);
28 fn test_range_from() {
29 let r = RangeFrom { start: 2 };
31 for (i, ri) in r.take(10).enumerate() {
33 assert!(ri >= 2 && ri < 12);
42 let _ = RangeTo { end: 42 };
46 fn test_full_range() {
52 fn test_range_inclusive() {
53 let mut r = RangeInclusive { start: 1i8, end: 2 };
54 assert_eq!(r.next(), Some(1));
55 assert_eq!(r.next(), Some(2));
56 assert_eq!(r.next(), None);
58 r = RangeInclusive { start: 127i8, end: 127 };
59 assert_eq!(r.next(), Some(127));
60 assert_eq!(r.next(), None);
62 r = RangeInclusive { start: -128i8, end: -128 };
63 assert_eq!(r.next_back(), Some(-128));
64 assert_eq!(r.next_back(), None);
67 r = RangeInclusive { start: 1, end: -1 };
68 assert_eq!(r.size_hint(), (0, Some(0)));
69 assert_eq!(r.next(), None);