about summary refs log tree commit diff
path: root/src/test/ui/cmp-default.rs
blob: bb5c39f5cdea9737b078f0b35cfa19846c89a958 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// run-pass

use std::cmp::Ordering;

// Test default methods in PartialOrd and PartialEq
//
#[derive(Debug)]
struct Fool(bool);

impl PartialEq for Fool {
    fn eq(&self, other: &Fool) -> bool {
        let Fool(this) = *self;
        let Fool(other) = *other;
        this != other
    }
}

struct Int(isize);

impl PartialEq for Int {
    fn eq(&self, other: &Int) -> bool {
        let Int(this) = *self;
        let Int(other) = *other;
        this == other
    }
}

impl PartialOrd for Int {
    fn partial_cmp(&self, other: &Int) -> Option<Ordering> {
        let Int(this) = *self;
        let Int(other) = *other;
        this.partial_cmp(&other)
    }
}

struct RevInt(isize);

impl PartialEq for RevInt {
    fn eq(&self, other: &RevInt) -> bool {
        let RevInt(this) = *self;
        let RevInt(other) = *other;
        this == other
    }
}

impl PartialOrd for RevInt {
    fn partial_cmp(&self, other: &RevInt) -> Option<Ordering> {
        let RevInt(this) = *self;
        let RevInt(other) = *other;
        other.partial_cmp(&this)
    }
}

pub fn main() {
    assert!(Int(2) >  Int(1));
    assert!(Int(2) >= Int(1));
    assert!(Int(1) >= Int(1));
    assert!(Int(1) <  Int(2));
    assert!(Int(1) <= Int(2));
    assert!(Int(1) <= Int(1));

    assert!(RevInt(2) <  RevInt(1));
    assert!(RevInt(2) <= RevInt(1));
    assert!(RevInt(1) <= RevInt(1));
    assert!(RevInt(1) >  RevInt(2));
    assert!(RevInt(1) >= RevInt(2));
    assert!(RevInt(1) >= RevInt(1));

    assert_eq!(Fool(true), Fool(false));
    assert!(Fool(true)  != Fool(true));
    assert!(Fool(false) != Fool(false));
    assert_eq!(Fool(false), Fool(true));
}