diff options
author | Ms2ger <Ms2ger@gmail.com> | 2016-06-08 11:55:47 +0200 |
---|---|---|
committer | Ms2ger <Ms2ger@gmail.com> | 2016-12-22 15:58:53 +0100 |
commit | 86d59212feef057dd2b36e99c22e6903b09993fd (patch) | |
tree | 3ca4204e8f9a778b1d9408579805fb7e9d970820 | |
parent | b843be49752c68926521a8b5f6b0405b1ff01e9b (diff) | |
download | servo-86d59212feef057dd2b36e99c22e6903b09993fd.tar.gz servo-86d59212feef057dd2b36e99c22e6903b09993fd.zip |
Introduce a script::test module to expose the APIs needed for unit tests.
-rw-r--r-- | components/script/lib.rs | 1 | ||||
-rw-r--r-- | components/script/test.rs | 55 | ||||
-rw-r--r-- | tests/unit/script/headers.rs | 17 | ||||
-rw-r--r-- | tests/unit/script/size_of.rs | 15 | ||||
-rw-r--r-- | tests/unit/script/textinput.rs | 2 |
5 files changed, 68 insertions, 22 deletions
diff --git a/components/script/lib.rs b/components/script/lib.rs index 508a2f13e9c..9c2bf9b7b46 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -118,6 +118,7 @@ mod serviceworker_manager; mod serviceworkerjob; mod stylesheet_loader; mod task_source; +pub mod test; pub mod textinput; mod timers; mod unpremultiplytable; diff --git a/components/script/test.rs b/components/script/test.rs new file mode 100644 index 00000000000..694998714a6 --- /dev/null +++ b/components/script/test.rs @@ -0,0 +1,55 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +pub use dom::bindings::str::{ByteString, DOMString}; +pub use dom::headers::normalize_value; + +pub mod size_of { + use dom::characterdata::CharacterData; + use dom::element::Element; + use dom::eventtarget::EventTarget; + use dom::htmldivelement::HTMLDivElement; + use dom::htmlelement::HTMLElement; + use dom::htmlspanelement::HTMLSpanElement; + use dom::node::Node; + use dom::text::Text; + use layout_wrapper::ServoThreadSafeLayoutNode; + use std::mem::size_of; + + pub fn CharacterData() -> usize { + size_of::<CharacterData>() + } + + pub fn Element() -> usize { + size_of::<Element>() + } + + pub fn EventTarget() -> usize { + size_of::<EventTarget>() + } + + pub fn HTMLDivElement() -> usize { + size_of::<HTMLDivElement>() + } + + pub fn HTMLElement() -> usize { + size_of::<HTMLElement>() + } + + pub fn HTMLSpanElement() -> usize { + size_of::<HTMLSpanElement>() + } + + pub fn Node() -> usize { + size_of::<Node>() + } + + pub fn ServoThreadSafeLayoutNode() -> usize { + size_of::<ServoThreadSafeLayoutNode>() + } + + pub fn Text() -> usize { + size_of::<Text>() + } +} diff --git a/tests/unit/script/headers.rs b/tests/unit/script/headers.rs index 5334056ec70..e990b706cdd 100644 --- a/tests/unit/script/headers.rs +++ b/tests/unit/script/headers.rs @@ -2,14 +2,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use script::dom::bindings::str::ByteString; -use script::dom::headers; +use script::test::{ByteString, normalize_value}; #[test] fn test_normalize_empty_bytestring() { // empty ByteString test let empty_bytestring = ByteString::new(vec![]); - let actual = headers::normalize_value(empty_bytestring); + let actual = normalize_value(empty_bytestring); let expected = ByteString::new(vec![]); assert_eq!(actual, expected); } @@ -18,7 +17,7 @@ fn test_normalize_empty_bytestring() { fn test_normalize_all_whitespace_bytestring() { // All whitespace test. A horizontal tab, a line feed, a carriage return , and a space let all_whitespace_bytestring = ByteString::new(vec![b'\t', b'\n', b'\r', b' ']); - let actual = headers::normalize_value(all_whitespace_bytestring); + let actual = normalize_value(all_whitespace_bytestring); let expected = ByteString::new(vec![]); assert_eq!(actual, expected); } @@ -27,7 +26,7 @@ fn test_normalize_all_whitespace_bytestring() { fn test_normalize_non_empty_no_whitespace_bytestring() { // Non-empty, no whitespace ByteString test let no_whitespace_bytestring = ByteString::new(vec![b'S', b'!']); - let actual = headers::normalize_value(no_whitespace_bytestring); + let actual = normalize_value(no_whitespace_bytestring); let expected = ByteString::new(vec![b'S', b'!']); assert_eq!(actual, expected); } @@ -36,7 +35,7 @@ fn test_normalize_non_empty_no_whitespace_bytestring() { fn test_normalize_non_empty_leading_whitespace_bytestring() { // Non-empty, leading whitespace, no trailing whitespace ByteString test let leading_whitespace_bytestring = ByteString::new(vec![b'\t', b'\n', b' ', b'\r', b'S', b'!']); - let actual = headers::normalize_value(leading_whitespace_bytestring); + let actual = normalize_value(leading_whitespace_bytestring); let expected = ByteString::new(vec![b'S', b'!']); assert_eq!(actual, expected); } @@ -45,7 +44,7 @@ fn test_normalize_non_empty_leading_whitespace_bytestring() { fn test_normalize_non_empty_no_leading_whitespace_trailing_whitespace_bytestring() { // Non-empty, no leading whitespace, but with trailing whitespace ByteString test let trailing_whitespace_bytestring = ByteString::new(vec![b'S', b'!', b'\t', b'\n', b' ', b'\r']); - let actual = headers::normalize_value(trailing_whitespace_bytestring); + let actual = normalize_value(trailing_whitespace_bytestring); let expected = ByteString::new(vec![b'S', b'!']); assert_eq!(actual, expected); } @@ -55,7 +54,7 @@ fn test_normalize_non_empty_leading_and_trailing_whitespace_bytestring() { // Non-empty, leading whitespace, and trailing whitespace ByteString test let whitespace_sandwich_bytestring = ByteString::new(vec![b'\t', b'\n', b' ', b'\r', b'S', b'!', b'\t', b'\n', b' ', b'\r']); - let actual = headers::normalize_value(whitespace_sandwich_bytestring); + let actual = normalize_value(whitespace_sandwich_bytestring); let expected = ByteString::new(vec![b'S', b'!']); assert_eq!(actual, expected); } @@ -68,7 +67,7 @@ fn test_normalize_non_empty_leading_trailing_and_internal_whitespace_bytestring( ByteString::new(vec![b'\t', b'\n', b' ', b'\r', b'S', b'\t', b'\n', b' ', b'\r', b'!', b'\t', b'\n', b' ', b'\r']); - let actual = headers::normalize_value(whitespace_bigmac_bytestring); + let actual = normalize_value(whitespace_bigmac_bytestring); let expected = ByteString::new(vec![b'S', b'\t', b'\n', b' ', b'\r', b'!']); assert_eq!(actual, expected); } diff --git a/tests/unit/script/size_of.rs b/tests/unit/script/size_of.rs index 3930180a9cf..64a2f37e67d 100644 --- a/tests/unit/script/size_of.rs +++ b/tests/unit/script/size_of.rs @@ -2,25 +2,16 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use script::dom::characterdata::CharacterData; -use script::dom::element::Element; -use script::dom::eventtarget::EventTarget; -use script::dom::htmldivelement::HTMLDivElement; -use script::dom::htmlelement::HTMLElement; -use script::dom::htmlspanelement::HTMLSpanElement; -use script::dom::node::Node; -use script::dom::text::Text; -use script::layout_wrapper::ServoThreadSafeLayoutNode; -use std::mem::size_of; +use script::test::size_of; // Macro so that we can stringify type names // I'd really prefer the tests themselves to be run at plugin time, // however rustc::middle doesn't have access to the full type data macro_rules! sizeof_checker ( - ($testname: ident, $t:ty, $known_size:expr) => ( + ($testname: ident, $t: ident, $known_size: expr) => ( #[test] fn $testname() { - let new = size_of::<$t>(); + let new = size_of::$t(); let old = $known_size; if new < old { panic!("Your changes have decreased the stack size of commonly used DOM struct {} from {} to {}. \ diff --git a/tests/unit/script/textinput.rs b/tests/unit/script/textinput.rs index 677132d393c..01e28433ed6 100644 --- a/tests/unit/script/textinput.rs +++ b/tests/unit/script/textinput.rs @@ -13,7 +13,7 @@ use msg::constellation_msg::CONTROL; #[cfg(target_os = "macos")] use msg::constellation_msg::SUPER; use script::clipboard_provider::DummyClipboardContext; -use script::dom::bindings::str::DOMString; +use script::test::DOMString; use script::textinput::{TextInput, TextPoint, Selection, Lines, Direction, SelectionDirection}; fn text_input(lines: Lines, s: &str) -> TextInput<DummyClipboardContext> { |