]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/shift.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / test / run-pass / shift.rs
1 // Copyright 2012 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 // Testing shifts for various combinations of integers
12 // Issue #1570
13
14 pub fn main() {
15     test_misc();
16     test_expr();
17     test_const();
18 }
19
20 fn test_misc() {
21     assert_eq!(1i << 1 << 1 << 1 << 1 << 1, 32);
22 }
23
24 fn test_expr() {
25     let v10 = 10 as uint;
26     let v4 = 4 as u8;
27     let v2 = 2 as u8;
28     assert_eq!(v10 >> v2 as uint, v2 as uint);
29     assert_eq!(v10 << v4 as uint, 160 as uint);
30
31     let v10 = 10 as u8;
32     let v4 = 4 as uint;
33     let v2 = 2 as uint;
34     assert_eq!(v10 >> v2 as uint, v2 as u8);
35     assert_eq!(v10 << v4 as uint, 160 as u8);
36
37     let v10 = 10 as int;
38     let v4 = 4 as i8;
39     let v2 = 2 as i8;
40     assert_eq!(v10 >> v2 as uint, v2 as int);
41     assert_eq!(v10 << v4 as uint, 160 as int);
42
43     let v10 = 10 as i8;
44     let v4 = 4 as int;
45     let v2 = 2 as int;
46     assert_eq!(v10 >> v2 as uint, v2 as i8);
47     assert_eq!(v10 << v4 as uint, 160 as i8);
48
49     let v10 = 10 as uint;
50     let v4 = 4 as int;
51     let v2 = 2 as int;
52     assert_eq!(v10 >> v2 as uint, v2 as uint);
53     assert_eq!(v10 << v4 as uint, 160 as uint);
54 }
55
56 fn test_const() {
57     static r1_1: uint = 10u >> 2u;
58     static r2_1: uint = 10u << 4u;
59     assert_eq!(r1_1, 2 as uint);
60     assert_eq!(r2_1, 160 as uint);
61
62     static r1_2: u8 = 10u8 >> 2u;
63     static r2_2: u8 = 10u8 << 4u;
64     assert_eq!(r1_2, 2 as u8);
65     assert_eq!(r2_2, 160 as u8);
66
67     static r1_3: int = 10 >> 2u;
68     static r2_3: int = 10 << 4u;
69     assert_eq!(r1_3, 2 as int);
70     assert_eq!(r2_3, 160 as int);
71
72     static r1_4: i8 = 10i8 >> 2u;
73     static r2_4: i8 = 10i8 << 4u;
74     assert_eq!(r1_4, 2 as i8);
75     assert_eq!(r2_4, 160 as i8);
76
77     static r1_5: uint = 10u >> 2u;
78     static r2_5: uint = 10u << 4u;
79     assert_eq!(r1_5, 2 as uint);
80     assert_eq!(r2_5, 160 as uint);
81 }