|
| 1 | +/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | + |
| 5 | +use std::borrow::Cow; |
| 6 | +use tokenizer::{Token, NumericValue, PercentageValue}; |
| 7 | + |
| 8 | +#[macro_export] |
| 9 | +macro_rules! size_of_test { |
| 10 | + ($testname: ident, $t: ty, $expected_size: expr) => { |
| 11 | + #[test] |
| 12 | + fn $testname() { |
| 13 | + let new = ::std::mem::size_of::<$t>(); |
| 14 | + let old = $expected_size; |
| 15 | + if new < old { |
| 16 | + panic!( |
| 17 | + "Your changes have decreased the stack size of {} from {} to {}. \ |
| 18 | + Good work! Please update the expected size in {}.", |
| 19 | + stringify!($t), old, new, file!() |
| 20 | + ) |
| 21 | + } else if new > old { |
| 22 | + panic!( |
| 23 | + "Your changes have increased the stack size of {} from {} to {}. \ |
| 24 | + Please consider choosing a design which avoids this increase. \ |
| 25 | + If you feel that the increase is necessary, update the size in {}.", |
| 26 | + stringify!($t), old, new, file!() |
| 27 | + ) |
| 28 | + } |
| 29 | + } |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +// These assume 64-bit |
| 34 | +size_of_test!(token, Token, 56); |
| 35 | +size_of_test!(numeric_value, NumericValue, 16); |
| 36 | +size_of_test!(percentage_value, PercentageValue, 16); |
| 37 | +size_of_test!(std_cow_str, Cow<'static, str>, 32); |
0 commit comments