]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/ranges-precedence.rs
Imported Upstream version 1.0.0~beta
[rustc.git] / src / test / run-pass / ranges-precedence.rs
CommitLineData
1a4d82fc
JJ
1// Copyright 2015 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 that the precedence of ranges is correct
12
1a4d82fc 13
c34b1796
AL
14// pretty-expanded FIXME #23616
15
1a4d82fc 16struct Foo {
c34b1796 17 foo: usize,
1a4d82fc
JJ
18}
19
20impl Foo {
c34b1796 21 fn bar(&self) -> usize { 5 }
1a4d82fc
JJ
22}
23
24fn main() {
25 let x = 1+3..4+5;
26 assert!(x == (4..9));
27
28 let x = 1..4+5;
29 assert!(x == (1..9));
30
31 let x = 1+3..4;
32 assert!(x == (4..4));
33
34 let a = Foo { foo: 3 };
35 let x = a.foo..a.bar();
36 assert!(x == (3..5));
37
38 let x = 1+3..;
39 assert!(x == (4..));
40 let x = ..1+3;
41 assert!(x == (..4));
42
c34b1796 43 let a = &[0, 1, 2, 3, 4, 5, 6];
1a4d82fc
JJ
44 let x = &a[1+1..2+2];
45 assert!(x == &a[2..4]);
46 let x = &a[..1+2];
47 assert!(x == &a[..3]);
48 let x = &a[1+2..];
49 assert!(x == &a[3..]);
50
51 for _i in 2+4..10-3 {}
85aaf69f
SL
52
53 let i = 42;
54 for _ in 1..i {}
55 for _ in 1.. { break; }
56
57 let x = [1]..[2];
58 assert!(x == (([1])..([2])));
59
60 let y = ..;
61 assert!(y == (..));
1a4d82fc 62}