1 // Copyright 2013 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 // no-pretty-expanded FIXME #15189
12 
13 #[cfg(feature = "use_core")]
14 extern crate core;
15 
16 #[macro_use]
17 extern crate derivative;
18 
19 #[derive(Derivative)]
20 #[derivative(
21     PartialEq = "feature_allow_slow_enum",
22     Eq,
23     PartialOrd = "feature_allow_slow_enum",
24     Ord = "feature_allow_slow_enum"
25 )]
26 enum E<T> {
27     V0,
28     V1(T),
29     V2(T, T),
30 }
31 
32 #[test]
main()33 fn main() {
34     let e0 = E::V0;
35     let e11 = E::V1(1);
36     let e12 = E::V1(2);
37     let e21 = E::V2(1, 1);
38     let e22 = E::V2(1, 2);
39 
40     // in order for both PartialOrd and Ord
41     let es = [e0, e11, e12, e21, e22];
42 
43     for (i, e1) in es.iter().enumerate() {
44         for (j, e2) in es.iter().enumerate() {
45             let ord = i.cmp(&j);
46 
47             let eq = i == j;
48             let lt = i < j;
49             let le = i <= j;
50             let gt = i > j;
51             let ge = i >= j;
52 
53             // PartialEq
54             assert_eq!(*e1 == *e2, eq);
55             assert_eq!(*e1 != *e2, !eq);
56 
57             // PartialOrd
58             assert_eq!(*e1 < *e2, lt);
59             assert_eq!(*e1 > *e2, gt);
60 
61             assert_eq!(*e1 <= *e2, le);
62             assert_eq!(*e1 >= *e2, ge);
63 
64             // Ord
65             assert_eq!(e1.cmp(e2), ord);
66         }
67     }
68 }
69