]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/small-enums-with-fields.rs
auto merge of #17513 : dradtke/rust/master, r=kballard
[rust.git] / src / test / run-pass / small-enums-with-fields.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 use std::mem::size_of;
14
15 #[deriving(PartialEq, Show)]
16 enum Either<T, U> { Left(T), Right(U) }
17
18 macro_rules! check {
19     ($t:ty, $sz:expr, $($e:expr, $s:expr),*) => {{
20         assert_eq!(size_of::<$t>(), $sz);
21         $({
22             static S: $t = $e;
23             let v: $t = $e;
24             assert_eq!(S, v);
25             assert_eq!(format!("{}", v).as_slice(), $s);
26             assert_eq!(format!("{}", S).as_slice(), $s);
27         });*
28     }}
29 }
30
31 pub fn main() {
32     check!(Option<u8>, 2,
33            None, "None",
34            Some(129u8), "Some(129)");
35     check!(Option<i16>, 4,
36            None, "None",
37            Some(-20000i16), "Some(-20000)");
38     check!(Either<u8, i8>, 2,
39            Either::Left(132u8), "Left(132)",
40            Either::Right(-32i8), "Right(-32)");
41     check!(Either<u8, i16>, 4,
42            Either::Left(132u8), "Left(132)",
43            Either::Right(-20000i16), "Right(-20000)");
44 }