diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2014-08-26 15:19:03 +0100 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2014-08-26 15:19:03 +0100 |
commit | dd44a7d24affbef1841bf8aa4c8c0e9c3c4989f0 (patch) | |
tree | 36b79ac45754dd85c264a180dcf0f053f42090ec /src | |
parent | b0c2e09ed74cc5ba7f95658c3d9d631852ae5773 (diff) | |
download | servo-dd44a7d24affbef1841bf8aa4c8c0e9c3c4989f0.tar.gz servo-dd44a7d24affbef1841bf8aa4c8c0e9c3c4989f0.zip |
Add tests for the bit_struct! macro.
The macro crate, when built with `--test`,
now depends on itself (a version of itself built without `--test`).
This is a bit unusal, but allows testing a syntax extension.
I did not feel like making a new crate just for this,
and these tests do not belong in any of the other existing crates.
Diffstat (limited to 'src')
-rw-r--r-- | src/components/macros/macros.rs | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/src/components/macros/macros.rs b/src/components/macros/macros.rs index f97a7cf2f1e..f26bd9e1dfa 100644 --- a/src/components/macros/macros.rs +++ b/src/components/macros/macros.rs @@ -6,13 +6,17 @@ #![crate_type = "rlib"] #![crate_type = "dylib"] -#![feature(macro_rules, plugin_registrar, quote)] +#![feature(macro_rules, plugin_registrar, quote, phase)] //! Exports macros for use in other Servo crates. #[cfg(test)] extern crate sync; +#[cfg(test)] +#[phase(plugin)] +extern crate macros; + extern crate rustc; extern crate syntax; @@ -181,9 +185,12 @@ macro_rules! lazy_init( ) +#[allow(dead_code)] #[cfg(test)] mod tests { use std::collections::hashmap::HashMap; + use std::mem::size_of; + lazy_init! { static ref NUMBER: uint = times_two(3); static ref VEC: [Box<uint>, ..3] = [box 1, box 2, box 3]; @@ -216,4 +223,72 @@ mod tests { assert_eq!(*NUMBER, 6); assert_eq!(*NUMBER, 6); } + + bit_struct! TestStruct64 { + f01, f02, f03, f04, f05, f06, f07, f08, f09, f10, + f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, + f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, + f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, + f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, + f51, f52, f53, f54, f55, f56, f57, f58, f59, f60, + f61, f62, f63, f64, + } + + bit_struct! TestStruct65 { + f01, f02, f03, f04, f05, f06, f07, f08, f09, f10, + f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, + f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, + f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, + f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, + f51, f52, f53, f54, f55, f56, f57, f58, f59, f60, + f61, f62, f63, f64, f65, + } + + #[test] + fn test_bit_struct() { + if cfg!(target_word_size = "64") { + // One and two 8-byte words + assert_eq!(size_of::<TestStruct64>(), 8) + assert_eq!(size_of::<TestStruct65>(), 16) + } else { + // Two and three 4-byte words + assert_eq!(size_of::<TestStruct64>(), 8) + assert_eq!(size_of::<TestStruct65>(), 12) + } + + let mut foo = TestStruct65::new(); + assert_eq!(foo.f01(), false); + assert_eq!(foo.f32(), false); + assert_eq!(foo.f33(), false); + assert_eq!(foo.f64(), false); + assert_eq!(foo.f65(), false); + + foo.set_f33(true); + assert_eq!(foo.f01(), false); + assert_eq!(foo.f32(), false); + assert_eq!(foo.f33(), true); + assert_eq!(foo.f64(), false); + assert_eq!(foo.f65(), false); + + foo.set_f01(false); + assert_eq!(foo.f01(), false); + assert_eq!(foo.f32(), false); + assert_eq!(foo.f33(), true); + assert_eq!(foo.f64(), false); + assert_eq!(foo.f65(), false); + + foo.set_f65(true); + assert_eq!(foo.f01(), false); + assert_eq!(foo.f32(), false); + assert_eq!(foo.f33(), true); + assert_eq!(foo.f64(), false); + assert_eq!(foo.f65(), true); + + foo.set_f33(false); + assert_eq!(foo.f01(), false); + assert_eq!(foo.f32(), false); + assert_eq!(foo.f33(), false); + assert_eq!(foo.f64(), false); + assert_eq!(foo.f65(), true); + } } |