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