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