mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Auto merge of #12924 - servo:selectors-ser, r=nox
Update selectors to 0.10, with ToCss serialization. <!-- Please describe your changes on the following line: --> r? @emilio --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12924) <!-- Reviewable:end -->
This commit is contained in:
commit
07b217368f
22 changed files with 203 additions and 69 deletions
|
@ -14,7 +14,7 @@ app_units = "0.3"
|
|||
cssparser = {version = "0.5.7", features = ["heap_size"]}
|
||||
euclid = "0.9"
|
||||
rustc-serialize = "0.3"
|
||||
selectors = {version = "0.9", features = ["heap_size"]}
|
||||
selectors = {version = "0.10", features = ["heap_size"]}
|
||||
string_cache = {version = "0.2.23", features = ["heap_size"]}
|
||||
style = {path = "../../../components/style"}
|
||||
style_traits = {path = "../../../components/style_traits"}
|
||||
|
|
|
@ -15,6 +15,9 @@ fn parse<T, F: Fn(&mut Parser) -> Result<T, ()>>(f: F, s: &str) -> Result<T, ()>
|
|||
// This is a macro so that the file/line information
|
||||
// is preserved in the panic
|
||||
macro_rules! assert_roundtrip {
|
||||
($fun:expr, $string:expr) => {
|
||||
assert_roundtrip!($fun, $string, $string);
|
||||
};
|
||||
($fun:expr, $input:expr, $output:expr) => {
|
||||
let parsed = $crate::parsing::parse($fun, $input)
|
||||
.expect(&format!("Failed to parse {}", $input));
|
||||
|
@ -31,3 +34,4 @@ macro_rules! assert_roundtrip {
|
|||
|
||||
mod basic_shape;
|
||||
mod position;
|
||||
mod selectors;
|
||||
|
|
22
tests/unit/style/parsing/selectors.rs
Normal file
22
tests/unit/style/parsing/selectors.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* 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::Parser;
|
||||
use selectors::parser::{Selector, ParserContext, parse_selector_list};
|
||||
use style::selector_impl::TheSelectorImpl;
|
||||
|
||||
fn parse(input: &mut Parser) -> Result<Selector<TheSelectorImpl>, ()> {
|
||||
let mut context = ParserContext::new();
|
||||
context.in_user_agent_stylesheet = true;
|
||||
context.namespace_prefixes.insert("svg".into(), ns!(svg));
|
||||
parse_selector_list(&context, input).map(|mut vec| vec.pop().unwrap())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_selectors() {
|
||||
assert_roundtrip!(parse, "div");
|
||||
assert_roundtrip!(parse, "svg|circle");
|
||||
assert_roundtrip!(parse, "p:before", "p::before");
|
||||
assert_roundtrip!(parse, "[border = \"0\"]:-servo-nonzero-border ~ ::-servo-details-summary");
|
||||
}
|
|
@ -8,7 +8,7 @@ use selectors::parser::*;
|
|||
use std::borrow::ToOwned;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use string_cache::{Atom, Namespace};
|
||||
use string_cache::{Atom, Namespace as NsAtom};
|
||||
use style::error_reporting::ParseErrorReporter;
|
||||
use style::keyframes::{Keyframe, KeyframeSelector, KeyframePercentage};
|
||||
use style::parser::ParserContextExtraData;
|
||||
|
@ -38,13 +38,19 @@ fn test_parse_stylesheet() {
|
|||
media: None,
|
||||
dirty_on_viewport_size_change: false,
|
||||
rules: vec![
|
||||
CSSRule::Namespace(None, Namespace(Atom::from("http://www.w3.org/1999/xhtml"))),
|
||||
CSSRule::Namespace {
|
||||
prefix: None,
|
||||
url: NsAtom(Atom::from("http://www.w3.org/1999/xhtml"))
|
||||
},
|
||||
CSSRule::Style(StyleRule {
|
||||
selectors: vec![
|
||||
Selector {
|
||||
compound_selectors: Arc::new(CompoundSelector {
|
||||
simple_selectors: vec![
|
||||
SimpleSelector::Namespace(Namespace(Atom::from("http://www.w3.org/1999/xhtml"))),
|
||||
SimpleSelector::Namespace(Namespace {
|
||||
prefix: None,
|
||||
url: NsAtom(Atom::from("http://www.w3.org/1999/xhtml"))
|
||||
}),
|
||||
SimpleSelector::LocalName(LocalName {
|
||||
name: atom!("input"),
|
||||
lower_name: atom!("input"),
|
||||
|
@ -52,7 +58,10 @@ fn test_parse_stylesheet() {
|
|||
SimpleSelector::AttrEqual(AttrSelector {
|
||||
name: atom!("type"),
|
||||
lower_name: atom!("type"),
|
||||
namespace: NamespaceConstraint::Specific(ns!()),
|
||||
namespace: NamespaceConstraint::Specific(Namespace {
|
||||
prefix: None,
|
||||
url: ns!()
|
||||
}),
|
||||
}, "hidden".to_owned(), CaseSensitivity::CaseInsensitive)
|
||||
],
|
||||
next: None,
|
||||
|
@ -74,7 +83,10 @@ fn test_parse_stylesheet() {
|
|||
Selector {
|
||||
compound_selectors: Arc::new(CompoundSelector {
|
||||
simple_selectors: vec![
|
||||
SimpleSelector::Namespace(Namespace(Atom::from("http://www.w3.org/1999/xhtml"))),
|
||||
SimpleSelector::Namespace(Namespace {
|
||||
prefix: None,
|
||||
url: NsAtom(Atom::from("http://www.w3.org/1999/xhtml"))
|
||||
}),
|
||||
SimpleSelector::LocalName(LocalName {
|
||||
name: atom!("html"),
|
||||
lower_name: atom!("html"),
|
||||
|
@ -88,7 +100,10 @@ fn test_parse_stylesheet() {
|
|||
Selector {
|
||||
compound_selectors: Arc::new(CompoundSelector {
|
||||
simple_selectors: vec![
|
||||
SimpleSelector::Namespace(Namespace(Atom::from("http://www.w3.org/1999/xhtml"))),
|
||||
SimpleSelector::Namespace(Namespace {
|
||||
prefix: None,
|
||||
url: NsAtom(Atom::from("http://www.w3.org/1999/xhtml"))
|
||||
}),
|
||||
SimpleSelector::LocalName(LocalName {
|
||||
name: atom!("body"),
|
||||
lower_name: atom!("body"),
|
||||
|
@ -113,12 +128,18 @@ fn test_parse_stylesheet() {
|
|||
Selector {
|
||||
compound_selectors: Arc::new(CompoundSelector {
|
||||
simple_selectors: vec![
|
||||
SimpleSelector::Namespace(Namespace(Atom::from("http://www.w3.org/1999/xhtml"))),
|
||||
SimpleSelector::Namespace(Namespace {
|
||||
prefix: None,
|
||||
url: NsAtom(Atom::from("http://www.w3.org/1999/xhtml"))
|
||||
}),
|
||||
SimpleSelector::Class(Atom::from("ok")),
|
||||
],
|
||||
next: Some((Arc::new(CompoundSelector {
|
||||
simple_selectors: vec![
|
||||
SimpleSelector::Namespace(Namespace(Atom::from("http://www.w3.org/1999/xhtml"))),
|
||||
SimpleSelector::Namespace(Namespace {
|
||||
prefix: None,
|
||||
url: NsAtom(Atom::from("http://www.w3.org/1999/xhtml"))
|
||||
}),
|
||||
SimpleSelector::ID(Atom::from("d1")),
|
||||
],
|
||||
next: None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue