2 #![allow(non_camel_case_types)]
4 use color::{red, green, blue, black, white, imaginary, purple, orange};
18 impl PartialEq for color {
19 fn eq(&self, other: &color) -> bool {
20 ((*self) as usize) == ((*other) as usize)
22 fn ne(&self, other: &color) -> bool { !(*self).eq(other) }
26 test_color(red, 0xff0000, "red".to_string());
27 test_color(green, 0x00ff00, "green".to_string());
28 test_color(blue, 0x0000ff, "blue".to_string());
29 test_color(black, 0x000000, "black".to_string());
30 test_color(white, 0xFFFFFF, "white".to_string());
31 test_color(imaginary, -1, "imaginary".to_string());
32 test_color(purple, 2, "purple".to_string());
33 test_color(orange, 4, "orange".to_string());
36 fn test_color(color: color, val: isize, name: String) {
37 //assert_eq!(unsafe::transmute(color), val);
38 assert_eq!(color as isize, val);
39 assert_eq!(get_color_alt(color), name);
40 assert_eq!(get_color_if(color), name);
43 fn get_color_alt(color: color) -> String {
45 red => {"red".to_string()}
46 green => {"green".to_string()}
47 blue => {"blue".to_string()}
48 black => {"black".to_string()}
49 white => {"white".to_string()}
50 imaginary => {"imaginary".to_string()}
51 purple => {"purple".to_string()}
52 orange => {"orange".to_string()}
56 fn get_color_if(color: color) -> String {
57 if color == red {"red".to_string()}
58 else if color == green {"green".to_string()}
59 else if color == blue {"blue".to_string()}
60 else if color == black {"black".to_string()}
61 else if color == white {"white".to_string()}
62 else if color == imaginary {"imaginary".to_string()}
63 else if color == purple {"purple".to_string()}
64 else if color == orange {"orange".to_string()}
65 else {"unknown".to_string()}