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.
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.
11 use color
::{red, green, blue, black, white, imaginary, purple, orange}
;
13 #[derive(Copy, Clone)]
25 impl PartialEq
for color
{
26 fn eq(&self, other
: &color
) -> bool
{
27 ((*self) as usize) == ((*other
) as usize)
29 fn ne(&self, other
: &color
) -> bool { !(*self).eq(other) }
33 test_color(red
, 0xff0000, "red".to_string());
34 test_color(green
, 0x00ff00, "green".to_string());
35 test_color(blue
, 0x0000ff, "blue".to_string());
36 test_color(black
, 0x000000, "black".to_string());
37 test_color(white
, 0xFFFFFF, "white".to_string());
38 test_color(imaginary
, -1, "imaginary".to_string());
39 test_color(purple
, 2, "purple".to_string());
40 test_color(orange
, 4, "orange".to_string());
43 fn test_color(color
: color
, val
: isize, name
: String
) {
44 //assert!(unsafe::transmute(color) == val);
45 assert_eq
!(color
as isize, val
);
46 assert
!(get_color_alt(color
) == name
);
47 assert
!(get_color_if(color
) == name
);
50 fn get_color_alt(color
: color
) -> String
{
52 red
=> {"red".to_string()}
53 green
=> {"green".to_string()}
54 blue
=> {"blue".to_string()}
55 black
=> {"black".to_string()}
56 white
=> {"white".to_string()}
57 imaginary
=> {"imaginary".to_string()}
58 purple
=> {"purple".to_string()}
59 orange
=> {"orange".to_string()}
63 fn get_color_if(color
: color
) -> String
{
64 if color
== red {"red".to_string()}
65 else if color
== green {"green".to_string()}
66 else if color
== blue {"blue".to_string()}
67 else if color
== black {"black".to_string()}
68 else if color
== white {"white".to_string()}
69 else if color
== imaginary {"imaginary".to_string()}
70 else if color
== purple {"purple".to_string()}
71 else if color
== orange {"orange".to_string()}
72 else {"unknown".to_string()}