mirror of
https://github.com/servo/servo.git
synced 2025-08-12 08:55:32 +01:00
Thread ParseError return values through CSS parsing.
This commit is contained in:
parent
58e39bfffa
commit
27ae1ef2e7
121 changed files with 2133 additions and 1505 deletions
|
@ -143,13 +143,13 @@ fn border_image_shorthand_should_parse_with_just_source() {
|
|||
#[test]
|
||||
fn border_image_outset_should_error_on_negative_length() {
|
||||
let result = parse(border_image_outset::parse, "-1em");
|
||||
assert_eq!(result, Err(()));
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn border_image_outset_should_error_on_negative_number() {
|
||||
let result = parse(border_image_outset::parse, "-15");
|
||||
assert_eq!(result, Err(()));
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
* 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 parsing::parse;
|
||||
use style::parser::Parse;
|
||||
use style::values::specified::image::*;
|
||||
use style_traits::ToCss;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* 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 cssparser::{Parser, ParserInput};
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use parsing::parse;
|
||||
use style::context::QuirksMode;
|
||||
|
@ -45,7 +45,8 @@ fn test_parsing_modes() {
|
|||
let context = ParserContext::new(Origin::Author, &url, &reporter,
|
||||
Some(CssRuleType::Style), PARSING_MODE_ALLOW_UNITLESS_LENGTH,
|
||||
QuirksMode::NoQuirks);
|
||||
let mut parser = Parser::new("1");
|
||||
let mut input = ParserInput::new("1");
|
||||
let mut parser = Parser::new(&mut input);
|
||||
let result = Length::parse(&context, &mut parser);
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(result.unwrap(), Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(1.))));
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
//! Tests for parsing and serialization of values/properties
|
||||
|
||||
use cssparser::Parser;
|
||||
use cssparser::{Parser, ParserInput};
|
||||
use euclid::size::TypedSize2D;
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use style::context::QuirksMode;
|
||||
|
@ -14,24 +14,38 @@ use style::parser::{PARSING_MODE_DEFAULT, ParserContext};
|
|||
use style::properties::{ComputedValues, StyleBuilder};
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use style::values::computed::{Context, ToComputedValue};
|
||||
use style_traits::ToCss;
|
||||
use style_traits::{ToCss, ParseError};
|
||||
|
||||
fn parse<T, F: Fn(&ParserContext, &mut Parser) -> Result<T, ()>>(f: F, s: &str) -> Result<T, ()> {
|
||||
fn parse<T, F>(f: F, s: &'static str) -> Result<T, ParseError<'static>>
|
||||
where F: for<'t> Fn(&ParserContext, &mut Parser<'static, 't>) -> Result<T, ParseError<'static>> {
|
||||
let mut input = ParserInput::new(s);
|
||||
parse_input(f, &mut input)
|
||||
}
|
||||
|
||||
fn parse_input<'i: 't, 't, T, F>(f: F, input: &'t mut ParserInput<'i>) -> Result<T, ParseError<'i>>
|
||||
where F: Fn(&ParserContext, &mut Parser<'i, 't>) -> Result<T, ParseError<'i>> {
|
||||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style),
|
||||
PARSING_MODE_DEFAULT,
|
||||
QuirksMode::NoQuirks);
|
||||
let mut parser = Parser::new(s);
|
||||
let mut parser = Parser::new(input);
|
||||
f(&context, &mut parser)
|
||||
}
|
||||
|
||||
fn parse_entirely<T, F: Fn(&ParserContext, &mut Parser) -> Result<T, ()>>(f: F, s: &str) -> Result<T, ()> {
|
||||
parse(|context, parser| parser.parse_entirely(|p| f(context, p)), s)
|
||||
fn parse_entirely<T, F>(f: F, s: &'static str) -> Result<T, ParseError<'static>>
|
||||
where F: for<'t> Fn(&ParserContext, &mut Parser<'static, 't>) -> Result<T, ParseError<'static>> {
|
||||
let mut input = ParserInput::new(s);
|
||||
parse_entirely_input(f, &mut input)
|
||||
}
|
||||
|
||||
fn assert_computed_serialization<C, F, T>(f: F, input: &str, output: &str)
|
||||
where F: Fn(&ParserContext, &mut Parser) -> Result<T, ()>,
|
||||
fn parse_entirely_input<'i: 't, 't, T, F>(f: F, input: &'t mut ParserInput<'i>) -> Result<T, ParseError<'i>>
|
||||
where F: Fn(&ParserContext, &mut Parser<'i, 't>) -> Result<T, ParseError<'i>> {
|
||||
parse_input(|context, parser| parser.parse_entirely(|p| f(context, p)), input)
|
||||
}
|
||||
|
||||
fn assert_computed_serialization<C, F, T>(f: F, input: &'static str, output: &str)
|
||||
where F: for<'t> Fn(&ParserContext, &mut Parser<'static, 't>) -> Result<T, ParseError<'static>>,
|
||||
T: ToComputedValue<ComputedValue=C>, C: ToCss
|
||||
{
|
||||
let viewport_size = TypedSize2D::new(0., 0.);
|
||||
|
@ -63,21 +77,23 @@ macro_rules! assert_roundtrip_with_context {
|
|||
assert_roundtrip_with_context!($fun, $string, $string);
|
||||
};
|
||||
($fun:expr, $input:expr, $output:expr) => {{
|
||||
let serialized = parse(|context, i| {
|
||||
let mut input = ::cssparser::ParserInput::new($input);
|
||||
let serialized = super::parse_input(|context, i| {
|
||||
let parsed = $fun(context, i)
|
||||
.expect(&format!("Failed to parse {}", $input));
|
||||
let serialized = ToCss::to_css_string(&parsed);
|
||||
assert_eq!(serialized, $output);
|
||||
Ok(serialized)
|
||||
}, $input).unwrap();
|
||||
}, &mut input).unwrap();
|
||||
|
||||
parse(|context, i| {
|
||||
let mut input = ::cssparser::ParserInput::new(&serialized);
|
||||
super::parse_input(|context, i| {
|
||||
let re_parsed = $fun(context, i)
|
||||
.expect(&format!("Failed to parse serialization {}", $input));
|
||||
let re_serialized = ToCss::to_css_string(&re_parsed);
|
||||
assert_eq!(serialized, re_serialized);
|
||||
Ok(())
|
||||
}, &serialized).unwrap()
|
||||
}, &mut input).unwrap()
|
||||
}}
|
||||
}
|
||||
|
||||
|
@ -86,13 +102,15 @@ macro_rules! assert_roundtrip {
|
|||
assert_roundtrip!($fun, $string, $string);
|
||||
};
|
||||
($fun:expr, $input:expr, $output:expr) => {
|
||||
let mut parser = Parser::new($input);
|
||||
let mut input = ParserInput::new($input);
|
||||
let mut parser = Parser::new(&mut input);
|
||||
let parsed = $fun(&mut parser)
|
||||
.expect(&format!("Failed to parse {}", $input));
|
||||
let serialized = ToCss::to_css_string(&parsed);
|
||||
assert_eq!(serialized, $output);
|
||||
|
||||
let mut parser = Parser::new(&serialized);
|
||||
let mut input = ParserInput::new(&serialized);
|
||||
let mut parser = Parser::new(&mut input);
|
||||
let re_parsed = $fun(&mut parser)
|
||||
.expect(&format!("Failed to parse serialization {}", $input));
|
||||
let re_serialized = ToCss::to_css_string(&re_parsed);
|
||||
|
@ -113,7 +131,7 @@ macro_rules! assert_parser_exhausted {
|
|||
|
||||
macro_rules! parse_longhand {
|
||||
($name:ident, $s:expr) => {
|
||||
parse($name::parse, $s).unwrap()
|
||||
parse($name::parse, $s).unwrap()
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +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 cssparser::{Parser, ToCss};
|
||||
use cssparser::{Parser, ParserInput, ToCss};
|
||||
use selectors::parser::SelectorList;
|
||||
use style::selector_parser::{SelectorImpl, SelectorParser};
|
||||
use style::stylesheets::{Origin, Namespaces};
|
||||
use style_traits::ParseError;
|
||||
|
||||
fn parse_selector(input: &mut Parser) -> Result<SelectorList<SelectorImpl>, ()> {
|
||||
fn parse_selector<'i, 't>(input: &mut Parser<'i, 't>) -> Result<SelectorList<SelectorImpl>, ParseError<'i>> {
|
||||
let mut ns = Namespaces::default();
|
||||
ns.prefixes.insert("svg".into(), (ns!(svg), ()));
|
||||
let parser = SelectorParser {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* 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 cssparser::{Parser, ParserInput};
|
||||
use style::stylesheets::supports_rule::SupportsCondition;
|
||||
use style_traits::ToCss;
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use app_units::Au;
|
||||
use cssparser::Parser;
|
||||
use cssparser::{Parser, ParserInput};
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use style::context::QuirksMode;
|
||||
use style::parser::{PARSING_MODE_ALLOW_ALL_NUMERIC_VALUES, ParserContext};
|
||||
|
@ -27,7 +27,8 @@ fn test_parsing_allo_all_numeric_values() {
|
|||
let context = ParserContext::new(Origin::Author, &url, &reporter,
|
||||
Some(CssRuleType::Style), PARSING_MODE_ALLOW_ALL_NUMERIC_VALUES,
|
||||
QuirksMode::NoQuirks);
|
||||
let mut parser = Parser::new("-1");
|
||||
let mut input = ParserInput::new("-1");
|
||||
let mut parser = Parser::new(&mut input);
|
||||
let result = Number::parse_non_negative(&context, &mut parser);
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(result.unwrap(), Number::new(-1.));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue