| 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 crate::cow_rc_str::CowRcStr; |
| 6 |
use crate::tokenizer::Token; |
| 7 |
|
| 8 |
macro_rules! size_of_test { |
| 9 |
($testname: ident, $t: ty, $expected_min_size: expr, $expected_max_size: expr) => { |
| 10 |
#[test] |
| 11 |
fn $testname() { |
| 12 |
let new = ::std::mem::size_of::<$t>(); |
| 13 |
if new < $expected_min_size { |
| 14 |
panic!( |
| 15 |
"Your changes have decreased the stack size of {} from {} to {}. \ |
| 16 |
Good work! Please update the expected size in {}.", |
| 17 |
stringify!($t), |
| 18 |
$expected_min_size, |
| 19 |
new, |
| 20 |
file!() |
| 21 |
) |
| 22 |
} else if new > $expected_max_size { |
| 23 |
panic!( |
| 24 |
"Your changes have increased the stack size of {} from {} to {}. \ |
| 25 |
Please consider choosing a design which avoids this increase. \ |
| 26 |
If you feel that the increase is necessary, update the size in {}.", |
| 27 |
stringify!($t), |
| 28 |
$expected_max_size, |
| 29 |
new, |
| 30 |
file!() |
| 31 |
) |
| 32 |
} |
| 33 |
} |
| 34 |
}; |
| 35 |
($testname: ident, $t: ty, $expected_size: expr) => { |
| 36 |
size_of_test!($testname, $t, $expected_size, $expected_size); |
| 37 |
}; |
| 38 |
} |
| 39 |
|
| 40 |
// Some of these assume 64-bit |
| 41 |
size_of_test!(token, Token, 32); |
| 42 |
size_of_test!(std_cow_str, std::borrow::Cow<'static, str>, 24, 32); |
| 43 |
size_of_test!(cow_rc_str, CowRcStr, 16); |
| 44 |
|
| 45 |
size_of_test!(tokenizer, crate::tokenizer::Tokenizer, 72); |
| 46 |
size_of_test!(parser_input, crate::parser::ParserInput, 136); |
| 47 |
size_of_test!(parser, crate::parser::Parser, 16); |
| 48 |
size_of_test!(source_position, crate::SourcePosition, 8); |
| 49 |
size_of_test!(parser_state, crate::ParserState, 24); |
| 50 |
|
| 51 |
size_of_test!(basic_parse_error, crate::BasicParseError, 40, 48); |
| 52 |
size_of_test!(parse_error_lower_bound, crate::ParseError<()>, 40, 48); |