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 style;
6
7 #[cfg(all(test, target_pointer_width = "64"))]
8 #[test]
size_of_specified_values()9 fn size_of_specified_values() {
10 use std::mem::size_of;
11 let threshold = 24;
12
13 let mut bad_properties = vec![];
14
15 macro_rules! check_property {
16 ( $( { $name: ident, $boxed: expr } )+ ) => {
17 $(
18 let size = size_of::<style::properties::longhands::$name::SpecifiedValue>();
19 let is_boxed = $boxed;
20 if (!is_boxed && size > threshold) || (is_boxed && size <= threshold) {
21 bad_properties.push((stringify!($name), size, is_boxed));
22 }
23 )+
24 }
25 }
26
27 longhand_properties_idents!(check_property);
28
29 let mut failing_messages = vec![];
30
31 for bad_prop in bad_properties {
32 if !bad_prop.2 {
33 failing_messages.push(
34 format!("Your changes have increased the size of {} SpecifiedValue to {}. The threshold is \
35 currently {}. SpecifiedValues affect size of PropertyDeclaration enum and \
36 increasing the size may negative affect style system performance. Please consider \
37 using `boxed=\"True\"` in this longhand.",
38 bad_prop.0, bad_prop.1, threshold));
39 } else if bad_prop.2 {
40 failing_messages.push(
41 format!("Your changes have decreased the size of {} SpecifiedValue to {}. Good work! \
42 The threshold is currently {}. Please consider removing `boxed=\"True\"` from this longhand.",
43 bad_prop.0, bad_prop.1, threshold));
44 }
45 }
46
47 if !failing_messages.is_empty() {
48 panic!("{}", failing_messages.join("\n\n"));
49 }
50 }
51