]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/cmp-default.rs
Rollup merge of #61499 - varkor:issue-53457, r=oli-obk
[rust.git] / src / test / run-pass / cmp-default.rs
1 use std::cmp::Ordering;
2
3 // Test default methods in PartialOrd and PartialEq
4 //
5 #[derive(Debug)]
6 struct Fool(bool);
7
8 impl PartialEq for Fool {
9     fn eq(&self, other: &Fool) -> bool {
10         let Fool(this) = *self;
11         let Fool(other) = *other;
12         this != other
13     }
14 }
15
16 struct Int(isize);
17
18 impl PartialEq for Int {
19     fn eq(&self, other: &Int) -> bool {
20         let Int(this) = *self;
21         let Int(other) = *other;
22         this == other
23     }
24 }
25
26 impl PartialOrd for Int {
27     fn partial_cmp(&self, other: &Int) -> Option<Ordering> {
28         let Int(this) = *self;
29         let Int(other) = *other;
30         this.partial_cmp(&other)
31     }
32 }
33
34 struct RevInt(isize);
35
36 impl PartialEq for RevInt {
37     fn eq(&self, other: &RevInt) -> bool {
38         let RevInt(this) = *self;
39         let RevInt(other) = *other;
40         this == other
41     }
42 }
43
44 impl PartialOrd for RevInt {
45     fn partial_cmp(&self, other: &RevInt) -> Option<Ordering> {
46         let RevInt(this) = *self;
47         let RevInt(other) = *other;
48         other.partial_cmp(&this)
49     }
50 }
51
52 pub fn main() {
53     assert!(Int(2) >  Int(1));
54     assert!(Int(2) >= Int(1));
55     assert!(Int(1) >= Int(1));
56     assert!(Int(1) <  Int(2));
57     assert!(Int(1) <= Int(2));
58     assert!(Int(1) <= Int(1));
59
60     assert!(RevInt(2) <  RevInt(1));
61     assert!(RevInt(2) <= RevInt(1));
62     assert!(RevInt(1) <= RevInt(1));
63     assert!(RevInt(1) >  RevInt(2));
64     assert!(RevInt(1) >= RevInt(2));
65     assert!(RevInt(1) >= RevInt(1));
66
67     assert_eq!(Fool(true), Fool(false));
68     assert!(Fool(true)  != Fool(true));
69     assert!(Fool(false) != Fool(false));
70     assert_eq!(Fool(false), Fool(true));
71 }