|
| 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 | +macro_rules! check { |
| 16 | + ($t:ty, $sz:expr, $($e:expr, $s:expr),*) => {{ |
| 17 | + assert_eq!(size_of::<$t>(), $sz); |
| 18 | + $({ |
| 19 | + static S: $t = $e; |
| 20 | + let v: $t = $e; |
| 21 | + assert_eq!(S, v); |
| 22 | + assert_eq!(format!("{:?}", v), ~$s); |
| 23 | + assert_eq!(format!("{:?}", S), ~$s); |
| 24 | + });* |
| 25 | + }} |
| 26 | +} |
| 27 | + |
| 28 | +pub fn main() { |
| 29 | + check!(Option<u8>, 2, |
| 30 | + None, "None", |
| 31 | + Some(129u8), "Some(129u8)"); |
| 32 | + check!(Option<i16>, 4, |
| 33 | + None, "None", |
| 34 | + Some(-20000i16), "Some(-20000i16)"); |
| 35 | + check!(Either<u8, i8>, 2, |
| 36 | + Left(132u8), "Left(132u8)", |
| 37 | + Right(-32i8), "Right(-32i8)"); |
| 38 | + check!(Either<u8, i16>, 4, |
| 39 | + Left(132u8), "Left(132u8)", |
| 40 | + Right(-20000i16), "Right(-20000i16)"); |
| 41 | +} |
0 commit comments