]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/tag-variant-disr-val.rs
6dc69656759de878423cf95d9a557fdcae9be6e6
[rustc.git] / src / test / run-pass / tag-variant-disr-val.rs
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
11 use color::{red, green, blue, black, white, imaginary, purple, orange};
12
13 #[derive(Copy, Clone)]
14 enum color {
15 red = 0xff0000,
16 green = 0x00ff00,
17 blue = 0x0000ff,
18 black = 0x000000,
19 white = 0xFFFFFF,
20 imaginary = -1,
21 purple = 1 << 1,
22 orange = 8 >> 1
23 }
24
25 impl PartialEq for color {
26 fn eq(&self, other: &color) -> bool {
27 ((*self) as usize) == ((*other) as usize)
28 }
29 fn ne(&self, other: &color) -> bool { !(*self).eq(other) }
30 }
31
32 pub fn main() {
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());
41 }
42
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);
48 }
49
50 fn get_color_alt(color: color) -> String {
51 match color {
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()}
60 }
61 }
62
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()}
73 }