]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/range.rs
auto merge of #20412 : nikomatsakis/rust/assoc-types, r=aturon
[rust.git] / src / test / run-pass / range.rs
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.
4 //
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.
10
11 // Test range syntax.
12
13 #![feature(slicing_syntax)]
14
15 fn foo() -> int { 42 }
16
17 pub fn main() {
18     let mut count = 0;
19     for i in 0u..10 {
20         assert!(i >= 0 && i < 10);
21         count += i;
22     }
23     assert!(count == 45);
24
25     let mut count = 0;
26     let mut range = 0u..10;
27     for i in range {
28         assert!(i >= 0 && i < 10);
29         count += i;
30     }
31     assert!(count == 45);
32
33     let mut count = 0;
34     let mut rf = 3u..;
35     for i in rf.take(10) {
36         assert!(i >= 3 && i < 13);
37         count += i;
38     }
39     assert!(count == 75);
40
41     let _ = 0u..4+4-3;
42     let _ = 0..foo();
43
44     let _ = ..42u;
45
46     // Test we can use two different types with a common supertype.
47     let x = &42i;
48     {
49         let y = 42i;
50         let _ = x..&y;
51     }
52 }