Add size_of tests for geckolib selectors

This commit is contained in:
Simon Sapin 2017-05-15 16:54:18 +02:00
parent cf2ae86373
commit fd357f08cf
8 changed files with 124 additions and 2 deletions

1
Cargo.lock generated
View file

@ -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)",
]

View file

@ -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"}

View file

@ -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;

View file

@ -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;

View file

@ -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),

View file

@ -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!() }
}

View file

@ -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"]}

View file

@ -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();