Graydon Hoare | d1affff | 2012-12-11 01:32:48 | [diff] [blame^] | 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 | |
Graydon Hoare | ce72993 | 2011-06-15 18:19:50 | [diff] [blame] | 11 | |
| 12 | |
Patrick Walton | 59ebe6a | 2012-01-20 02:31:08 | [diff] [blame] | 13 | enum foo { large, small, } |
Graydon Hoare | 9f0a6c2 | 2010-09-21 18:47:10 | [diff] [blame] | 14 | |
Patrick Walton | 9653436 | 2012-08-27 23:26:35 | [diff] [blame] | 15 | impl foo : cmp::Eq { |
Patrick Walton | 318e534 | 2012-11-15 02:59:30 | [diff] [blame] | 16 | pure fn eq(&self, other: &foo) -> bool { |
| 17 | ((*self) as uint) == ((*other) as uint) |
Patrick Walton | 9653436 | 2012-08-27 23:26:35 | [diff] [blame] | 18 | } |
Patrick Walton | 318e534 | 2012-11-15 02:59:30 | [diff] [blame] | 19 | pure fn ne(&self, other: &foo) -> bool { !(*self).eq(other) } |
Patrick Walton | 9653436 | 2012-08-27 23:26:35 | [diff] [blame] | 20 | } |
| 21 | |
Graydon Hoare | 9f0a6c2 | 2010-09-21 18:47:10 | [diff] [blame] | 22 | fn main() { |
Patrick Walton | 9653436 | 2012-08-27 23:26:35 | [diff] [blame] | 23 | let a = (1, 2, 3); |
| 24 | let b = (1, 2, 3); |
Graydon Hoare | ce72993 | 2011-06-15 18:19:50 | [diff] [blame] | 25 | assert (a == b); |
Patrick Walton | 9653436 | 2012-08-27 23:26:35 | [diff] [blame] | 26 | assert (a != (1, 2, 4)); |
| 27 | assert (a < (1, 2, 4)); |
| 28 | assert (a <= (1, 2, 4)); |
| 29 | assert ((1, 2, 4) > a); |
| 30 | assert ((1, 2, 4) >= a); |
Marijn Haverbeke | df7f21d | 2011-07-27 12:19:39 | [diff] [blame] | 31 | let x = large; |
| 32 | let y = small; |
Graydon Hoare | ce72993 | 2011-06-15 18:19:50 | [diff] [blame] | 33 | assert (x != y); |
| 34 | assert (x == large); |
| 35 | assert (x != small); |
Brian Anderson | 518dc52 | 2011-08-19 22:16:48 | [diff] [blame] | 36 | } |