]> git.lizzy.rs Git - rust.git/blob - src/test/ui/structs-enums/tag-variant-disr-val.rs
Rollup merge of #97317 - GuillaumeGomez:gui-settings-text-click, r=jsha
[rust.git] / src / test / ui / structs-enums / tag-variant-disr-val.rs
1 // run-pass
2 #![allow(non_camel_case_types)]
3
4 use color::{red, green, blue, black, white, imaginary, purple, orange};
5
6 #[derive(Copy, Clone)]
7 enum color {
8     red = 0xff0000,
9     green = 0x00ff00,
10     blue = 0x0000ff,
11     black = 0x000000,
12     white = 0xFFFFFF,
13     imaginary = -1,
14     purple = 1 << 1,
15     orange = 8 >> 1
16 }
17
18 impl PartialEq for color {
19     fn eq(&self, other: &color) -> bool {
20         ((*self) as usize) == ((*other) as usize)
21     }
22     fn ne(&self, other: &color) -> bool { !(*self).eq(other) }
23 }
24
25 pub fn main() {
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());
34 }
35
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);
41 }
42
43 fn get_color_alt(color: color) -> String {
44     match color {
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()}
53     }
54 }
55
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()}
66 }