diff options
-rw-r--r-- | mk/check.mk | 7 | ||||
-rw-r--r-- | src/components/macros/macros.rs | 77 |
2 files changed, 81 insertions, 3 deletions
diff --git a/mk/check.mk b/mk/check.mk index 1632ca1d5ff..e885e6e3ec3 100644 --- a/mk/check.mk +++ b/mk/check.mk @@ -21,10 +21,13 @@ $(foreach submodule,$(SUBMODULES),\ $(eval $(call DEF_SUBMODULE_TEST_RULES,$(submodule)))) +DEPS_test_macros = $(DONE_macros) +RFLAGS_test_macros = -L $(B)src/components/macros + define DEF_LIB_CRATE_TEST_RULES -servo-test-$(1): $$(DEPS_$(1)) +servo-test-$(1): $$(DEPS_$(1)) $$(DEPS_test_$(1)) @$$(call E, compile: servo-test-$(1)) - $$(Q)$$(RUSTC) $(strip $(TARGET_FLAGS) $(CFG_RUSTC_FLAGS)) $$(RFLAGS_$(1)) --test -o $$@ $$< + $$(Q)$$(RUSTC) $(strip $(TARGET_FLAGS) $(CFG_RUSTC_FLAGS)) $$(RFLAGS_$(1)) $$(RFLAGS_test_$(1)) --test -o $$@ $$< .PHONY: check-servo-$(1) check-servo-$(1): servo-test-$(1) 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); + } } |