aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2017-05-15 16:54:18 +0200
committerSimon Sapin <simon.sapin@exyr.org>2017-05-16 10:24:41 +0200
commitfd357f08cfdcabfa7708fe3f8ab55d9e5d075c48 (patch)
tree2a1d8cefaad4f20d64c9b545b5f32d88db9f2619
parentcf2ae86373cb4565f37d6a204a0d0c8096fa7e6c (diff)
downloadservo-fd357f08cfdcabfa7708fe3f8ab55d9e5d075c48.tar.gz
servo-fd357f08cfdcabfa7708fe3f8ab55d9e5d075c48.zip
Add size_of tests for geckolib selectors
-rw-r--r--Cargo.lock1
-rw-r--r--components/selectors/Cargo.toml6
-rw-r--r--components/selectors/gecko_like_types.rs29
-rw-r--r--components/selectors/lib.rs3
-rw-r--r--components/selectors/parser.rs2
-rw-r--r--components/selectors/size_of_tests.rs66
-rw-r--r--tests/unit/stylo/Cargo.toml2
-rw-r--r--tests/unit/stylo/size_of.rs17
8 files changed, 124 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2b9e5c06ab8..3610f0cf2cb 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2444,6 +2444,7 @@ dependencies = [
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"precomputed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "size_of_test 0.0.1",
"smallvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
diff --git a/components/selectors/Cargo.toml b/components/selectors/Cargo.toml
index 20ddf3b8ad2..ceef176eae1 100644
--- a/components/selectors/Cargo.toml
+++ b/components/selectors/Cargo.toml
@@ -17,6 +17,9 @@ path = "lib.rs"
# https://github.com/servo/servo/issues/16710
doctest = false
+[features]
+gecko_like_types = []
+
[dependencies]
bitflags = "0.7"
matches = "0.1"
@@ -24,3 +27,6 @@ cssparser = "0.13.3"
fnv = "1.0"
precomputed-hash = "0.1"
smallvec = "0.3"
+
+[dev-dependencies]
+size_of_test = {path = "../size_of_test"}
diff --git a/components/selectors/gecko_like_types.rs b/components/selectors/gecko_like_types.rs
new file mode 100644
index 00000000000..b00d8d95667
--- /dev/null
+++ b/components/selectors/gecko_like_types.rs
@@ -0,0 +1,29 @@
+/* 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/. */
+
+//! These types need to have the same size and alignment as the respectively corresponding
+//! types in components/style/gecko/selector_parser.rs
+
+#[derive(Eq, PartialEq, Clone, Debug, Hash)]
+#[allow(dead_code)]
+pub enum PseudoClass {
+ Bare,
+ String(Box<[u16]>),
+ MozAny(Box<[()]>),
+}
+
+#[derive(Eq, PartialEq, Clone, Debug, Hash)]
+pub enum PseudoElement {
+ A,
+ B,
+}
+
+#[derive(Eq, PartialEq, Clone, Debug)]
+pub struct PseudoElementSelector(PseudoElement, u64);
+
+#[derive(Eq, PartialEq, Clone, Debug, Hash, Default)]
+pub struct Atom(usize);
+
+#[derive(Eq, PartialEq, Clone, Hash)]
+pub struct Impl;
diff --git a/components/selectors/lib.rs b/components/selectors/lib.rs
index 452e47963c7..d352d2f1d3c 100644
--- a/components/selectors/lib.rs
+++ b/components/selectors/lib.rs
@@ -7,12 +7,15 @@
#[macro_use] extern crate matches;
extern crate fnv;
extern crate precomputed_hash;
+#[cfg(test)] #[macro_use] extern crate size_of_test;
extern crate smallvec;
pub mod arcslice;
pub mod bloom;
pub mod matching;
pub mod parser;
+#[cfg(test)] mod size_of_tests;
+#[cfg(any(test, feature = "gecko_like_types"))] pub mod gecko_like_types;
mod tree;
pub mod visitor;
diff --git a/components/selectors/parser.rs b/components/selectors/parser.rs
index 7c0f53ab0a6..5dd7760adc2 100644
--- a/components/selectors/parser.rs
+++ b/components/selectors/parser.rs
@@ -1505,7 +1505,7 @@ pub mod tests {
}
}
- fn parse_pseudo_element(&self, name: Cow<str>, input: &mut CssParser)
+ fn parse_pseudo_element(&self, name: Cow<str>, _input: &mut CssParser)
-> Result<PseudoElement, ()> {
match_ignore_ascii_case! { &name,
"before" => Ok(PseudoElement::Before),
diff --git a/components/selectors/size_of_tests.rs b/components/selectors/size_of_tests.rs
new file mode 100644
index 00000000000..1d06278abd5
--- /dev/null
+++ b/components/selectors/size_of_tests.rs
@@ -0,0 +1,66 @@
+/* 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/. */
+
+use cssparser::ToCss;
+use gecko_like_types::*;
+use parser::*;
+use precomputed_hash::PrecomputedHash;
+use std::fmt;
+use visitor::SelectorVisitor;
+
+size_of_test!(size_of_selector, Selector<Impl>, 72);
+size_of_test!(size_of_pseudo_element, PseudoElementSelector, 16);
+size_of_test!(size_of_selector_inner, SelectorInner<Impl>, 40);
+size_of_test!(size_of_complex_selector, ComplexSelector<Impl>, 24);
+
+size_of_test!(size_of_component, Component<Impl>, 64);
+size_of_test!(size_of_attr_selector, AttrSelector<Impl>, 48);
+size_of_test!(size_of_pseudo_class, PseudoClass, 24);
+
+
+// Boilerplate
+
+impl SelectorImpl for Impl {
+ type AttrValue = Atom;
+ type Identifier = Atom;
+ type ClassName = Atom;
+ type LocalName = Atom;
+ type NamespaceUrl = Atom;
+ type NamespacePrefix = Atom;
+ type BorrowedLocalName = Atom;
+ type BorrowedNamespaceUrl = Atom;
+ type NonTSPseudoClass = PseudoClass;
+ type PseudoElementSelector = PseudoElementSelector;
+}
+
+impl SelectorMethods for PseudoClass {
+ type Impl = Impl;
+
+ fn visit<V>(&self, _visitor: &mut V) -> bool
+ where V: SelectorVisitor<Impl = Self::Impl> { unimplemented!() }
+}
+
+impl ToCss for PseudoClass {
+ fn to_css<W>(&self, _: &mut W) -> fmt::Result where W: fmt::Write { unimplemented!() }
+}
+
+impl ToCss for PseudoElementSelector {
+ fn to_css<W>(&self, _: &mut W) -> fmt::Result where W: fmt::Write { unimplemented!() }
+}
+
+impl fmt::Display for Atom {
+ fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { unimplemented!() }
+}
+
+impl From<String> for Atom {
+ fn from(_: String) -> Self { unimplemented!() }
+}
+
+impl<'a> From<&'a str> for Atom {
+ fn from(_: &'a str) -> Self { unimplemented!() }
+}
+
+impl PrecomputedHash for Atom {
+ fn precomputed_hash(&self) -> u32 { unimplemented!() }
+}
diff --git a/tests/unit/stylo/Cargo.toml b/tests/unit/stylo/Cargo.toml
index 6ea16ea5ddc..8c6478be76e 100644
--- a/tests/unit/stylo/Cargo.toml
+++ b/tests/unit/stylo/Cargo.toml
@@ -22,7 +22,7 @@ euclid = "0.11"
libc = "0.2"
log = {version = "0.3.5", features = ["release_max_level_info"]}
parking_lot = "0.3"
-selectors = {path = "../../../components/selectors"}
+selectors = {path = "../../../components/selectors", features = ["gecko_like_types"]}
style_traits = {path = "../../../components/style_traits"}
geckoservo = {path = "../../../ports/geckolib"}
style = {path = "../../../components/style", features = ["gecko"]}
diff --git a/tests/unit/stylo/size_of.rs b/tests/unit/stylo/size_of.rs
index f43163b82c6..4ae541c8de0 100644
--- a/tests/unit/stylo/size_of.rs
+++ b/tests/unit/stylo/size_of.rs
@@ -2,6 +2,23 @@
* 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 selectors::gecko_like_types as dummies;
+use std::mem::{size_of, align_of};
+use style;
+use style::gecko::selector_parser as real;
+
+#[test]
+fn size_of_selectors_dummy_types() {
+ assert_eq!(size_of::<dummies::PseudoClass>(), size_of::<real::NonTSPseudoClass>());
+ assert_eq!(align_of::<dummies::PseudoClass>(), align_of::<real::NonTSPseudoClass>());
+
+ assert_eq!(size_of::<dummies::PseudoElementSelector>(), size_of::<real::PseudoElementSelector>());
+ assert_eq!(align_of::<dummies::PseudoElementSelector>(), align_of::<real::PseudoElementSelector>());
+
+ assert_eq!(size_of::<dummies::Atom>(), size_of::<style::Atom>());
+ assert_eq!(align_of::<dummies::Atom>(), align_of::<style::Atom>());
+}
+
#[test]
fn size_of_property_declaration() {
::style::properties::test_size_of_property_declaration();