]> git.proxmox.com Git - rustc.git/blob - src/tools/miri/tests/run-pass/binops.rs
New upstream version 1.22.1+dfsg1
[rustc.git] / src / tools / miri / tests / run-pass / binops.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 // Binop corner cases
12
13 fn test_nil() {
14 assert_eq!((), ());
15 assert!((!(() != ())));
16 assert!((!(() < ())));
17 assert!((() <= ()));
18 assert!((!(() > ())));
19 assert!((() >= ()));
20 }
21
22 fn test_bool() {
23 assert!((!(true < false)));
24 assert!((!(true <= false)));
25 assert!((true > false));
26 assert!((true >= false));
27
28 assert!((false < true));
29 assert!((false <= true));
30 assert!((!(false > true)));
31 assert!((!(false >= true)));
32
33 // Bools support bitwise binops
34 assert_eq!(false & false, false);
35 assert_eq!(true & false, false);
36 assert_eq!(true & true, true);
37 assert_eq!(false | false, false);
38 assert_eq!(true | false, true);
39 assert_eq!(true | true, true);
40 assert_eq!(false ^ false, false);
41 assert_eq!(true ^ false, true);
42 assert_eq!(true ^ true, false);
43 }
44
45 fn test_ptr() {
46 unsafe {
47 let p1: *const u8 = ::std::mem::transmute(0_usize);
48 let p2: *const u8 = ::std::mem::transmute(0_usize);
49 let p3: *const u8 = ::std::mem::transmute(1_usize);
50
51 assert_eq!(p1, p2);
52 assert!(p1 != p3);
53 assert!(p1 < p3);
54 assert!(p1 <= p3);
55 assert!(p3 > p1);
56 assert!(p3 >= p3);
57 assert!(p1 <= p2);
58 assert!(p1 >= p2);
59 }
60 }
61
62 #[derive(PartialEq, Debug)]
63 struct P {
64 x: isize,
65 y: isize,
66 }
67
68 fn p(x: isize, y: isize) -> P {
69 P {
70 x: x,
71 y: y
72 }
73 }
74
75 fn test_class() {
76 let q = p(1, 2);
77 let mut r = p(1, 2);
78
79 assert_eq!(q, r);
80 r.y = 17;
81 assert!((r.y != q.y));
82 assert_eq!(r.y, 17);
83 assert!((q != r));
84 }
85
86 pub fn main() {
87 test_nil();
88 test_bool();
89 test_ptr();
90 test_class();
91 }