]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/enum-discrim-width-stuff.rs
auto merge of #13600 : brandonw/rust/master, r=brson
[rust.git] / src / test / run-pass / enum-discrim-width-stuff.rs
1 // Copyright 2013 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 #![feature(macro_rules)]
12
13 macro_rules! check {
14     ($m:ident, $t:ty, $v:expr) => {{
15         mod $m {
16             use std::mem::size_of;
17             enum E {
18                 V = $v,
19                 A = 0
20             }
21             static C: E = V;
22             pub fn check() {
23                 assert_eq!(size_of::<E>(), size_of::<$t>());
24                 assert_eq!(V as $t, $v);
25                 assert_eq!(C as $t, $v);
26                 assert_eq!(format!("{:?}", V), ~"V");
27                 assert_eq!(format!("{:?}", C), ~"V");
28             }
29         }
30         $m::check();
31     }}
32 }
33
34 pub fn main() {
35     check!(a, u8, 0x17);
36     check!(b, u8, 0xe8);
37     check!(c, u16, 0x1727);
38     check!(d, u16, 0xe8d8);
39     check!(e, u32, 0x17273747);
40     check!(f, u32, 0xe8d8c8b8);
41     check!(g, u64, 0x1727374757677787u64);
42     check!(h, u64, 0xe8d8c8b8a8988878u64);
43
44     check!(z, i8, 0x17);
45     check!(y, i8, -0x17);
46     check!(x, i16, 0x1727);
47     check!(w, i16, -0x1727);
48     check!(v, i32, 0x17273747);
49     check!(u, i32, -0x17273747);
50     check!(t, i64, 0x1727374757677787);
51     check!(s, i64, -0x1727374757677787);
52
53     enum Simple { A, B }
54     assert_eq!(::std::mem::size_of::<Simple>(), 1);
55 }