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.
23 fn eq(&self, other: &color) -> bool {
24 ((*self) as uint) == ((*other) as uint)
26 fn ne(&self, other: &color) -> bool { !(*self).eq(other) }
30 test_color(red, 0xff0000, "red".to_strbuf());
31 test_color(green, 0x00ff00, "green".to_strbuf());
32 test_color(blue, 0x0000ff, "blue".to_strbuf());
33 test_color(black, 0x000000, "black".to_strbuf());
34 test_color(white, 0xFFFFFF, "white".to_strbuf());
35 test_color(imaginary, -1, "imaginary".to_strbuf());
36 test_color(purple, 2, "purple".to_strbuf());
37 test_color(orange, 4, "orange".to_strbuf());
40 fn test_color(color: color, val: int, name: StrBuf) {
41 //assert!(unsafe::transmute(color) == val);
42 assert_eq!(color as int, val);
43 assert_eq!(color as f64, val as f64);
44 assert!(get_color_alt(color) == name);
45 assert!(get_color_if(color) == name);
48 fn get_color_alt(color: color) -> StrBuf {
50 red => {"red".to_strbuf()}
51 green => {"green".to_strbuf()}
52 blue => {"blue".to_strbuf()}
53 black => {"black".to_strbuf()}
54 white => {"white".to_strbuf()}
55 imaginary => {"imaginary".to_strbuf()}
56 purple => {"purple".to_strbuf()}
57 orange => {"orange".to_strbuf()}
61 fn get_color_if(color: color) -> StrBuf {
62 if color == red {"red".to_strbuf()}
63 else if color == green {"green".to_strbuf()}
64 else if color == blue {"blue".to_strbuf()}
65 else if color == black {"black".to_strbuf()}
66 else if color == white {"white".to_strbuf()}
67 else if color == imaginary {"imaginary".to_strbuf()}
68 else if color == purple {"purple".to_strbuf()}
69 else if color == orange {"orange".to_strbuf()}
70 else {"unknown".to_strbuf()}