mirror of
https://github.com/servo/servo.git
synced 2025-08-17 11:25:35 +01:00
style: Avoid cloning all over the error reporter.
This commit is contained in:
parent
eaf27ccfa0
commit
b4de69e3eb
36 changed files with 186 additions and 154 deletions
|
@ -15,7 +15,8 @@ use style::stylesheets::Origin;
|
|||
#[test]
|
||||
fn background_shorthand_should_parse_all_available_properties_when_specified() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("url(\"http://servo/test.png\") top center / 200px 200px repeat-x fixed padding-box \
|
||||
content-box red");
|
||||
let result = background::parse_value(&context, &mut parser).unwrap();
|
||||
|
@ -34,7 +35,8 @@ fn background_shorthand_should_parse_all_available_properties_when_specified() {
|
|||
#[test]
|
||||
fn background_shorthand_should_parse_when_some_fields_set() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("14px 40px repeat-y");
|
||||
let result = background::parse_value(&context, &mut parser).unwrap();
|
||||
|
||||
|
@ -64,7 +66,8 @@ fn background_shorthand_should_parse_when_some_fields_set() {
|
|||
#[test]
|
||||
fn background_shorthand_should_parse_comma_separated_declarations() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("url(\"http://servo/test.png\") top left no-repeat, url(\"http://servo/test.png\") \
|
||||
center / 100% 100% no-repeat, white");
|
||||
let result = background::parse_value(&context, &mut parser).unwrap();
|
||||
|
@ -85,7 +88,8 @@ fn background_shorthand_should_parse_comma_separated_declarations() {
|
|||
#[test]
|
||||
fn background_shorthand_should_parse_position_and_size_correctly() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("7px 4px");
|
||||
let result = background::parse_value(&context, &mut parser).unwrap();
|
||||
|
||||
|
@ -109,7 +113,8 @@ fn background_shorthand_should_parse_position_and_size_correctly() {
|
|||
#[test]
|
||||
fn background_shorthand_should_parse_origin_and_clip_correctly() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("padding-box content-box");
|
||||
let result = background::parse_value(&context, &mut parser).unwrap();
|
||||
|
||||
|
|
|
@ -15,7 +15,8 @@ use style_traits::ToCss;
|
|||
#[test]
|
||||
fn border_image_shorthand_should_parse_when_all_properties_specified() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill / 20px 40px / 10px \
|
||||
round stretch");
|
||||
let result = border_image::parse_value(&context, &mut parser).unwrap();
|
||||
|
@ -31,7 +32,8 @@ fn border_image_shorthand_should_parse_when_all_properties_specified() {
|
|||
#[test]
|
||||
fn border_image_shorthand_should_parse_without_width() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill / / 10px round stretch");
|
||||
let result = border_image::parse_value(&context, &mut parser).unwrap();
|
||||
|
||||
|
@ -46,7 +48,8 @@ fn border_image_shorthand_should_parse_without_width() {
|
|||
#[test]
|
||||
fn border_image_shorthand_should_parse_without_outset() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill / 20px 40px round");
|
||||
let result = border_image::parse_value(&context, &mut parser).unwrap();
|
||||
|
||||
|
@ -61,7 +64,8 @@ fn border_image_shorthand_should_parse_without_outset() {
|
|||
#[test]
|
||||
fn border_image_shorthand_should_parse_without_width_or_outset() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill round");
|
||||
let result = border_image::parse_value(&context, &mut parser).unwrap();
|
||||
|
||||
|
@ -76,7 +80,8 @@ fn border_image_shorthand_should_parse_without_width_or_outset() {
|
|||
#[test]
|
||||
fn border_image_shorthand_should_parse_with_just_source() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("linear-gradient(red, blue)");
|
||||
let result = border_image::parse_value(&context, &mut parser).unwrap();
|
||||
|
||||
|
@ -91,7 +96,8 @@ fn border_image_shorthand_should_parse_with_just_source() {
|
|||
#[test]
|
||||
fn border_image_outset_should_error_on_negative_length() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("-1em");
|
||||
let result = border_image_outset::parse(&context, &mut parser);
|
||||
assert_eq!(result, Err(()));
|
||||
|
@ -100,7 +106,8 @@ fn border_image_outset_should_error_on_negative_length() {
|
|||
#[test]
|
||||
fn border_image_outset_should_error_on_negative_number() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("-15");
|
||||
let result = border_image_outset::parse(&context, &mut parser);
|
||||
assert_eq!(result, Err(()));
|
||||
|
@ -109,7 +116,8 @@ fn border_image_outset_should_error_on_negative_number() {
|
|||
#[test]
|
||||
fn border_image_outset_should_return_number_on_plain_zero() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("0");
|
||||
let result = border_image_outset::parse(&context, &mut parser);
|
||||
assert_eq!(result.unwrap(), parse_longhand!(border_image_outset, "0"));
|
||||
|
@ -118,7 +126,8 @@ fn border_image_outset_should_return_number_on_plain_zero() {
|
|||
#[test]
|
||||
fn border_image_outset_should_return_length_on_length_zero() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("0em");
|
||||
let result = border_image_outset::parse(&context, &mut parser);
|
||||
assert_eq!(result.unwrap(), parse_longhand!(border_image_outset, "0em"));
|
||||
|
|
|
@ -19,7 +19,8 @@ fn test_column_width() {
|
|||
assert_roundtrip_with_context!(column_width::parse, "0.3vw");
|
||||
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
|
||||
let mut negative = Parser::new("-6px");
|
||||
assert!(column_width::parse(&context, &mut negative).is_err());
|
||||
|
@ -35,7 +36,8 @@ fn test_column_gap() {
|
|||
assert_roundtrip_with_context!(column_gap::parse, "0.3vw");
|
||||
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
|
||||
let mut negative = Parser::new("-6px");
|
||||
assert!(column_gap::parse(&context, &mut negative).is_err());
|
||||
|
|
|
@ -38,7 +38,8 @@ fn test_clip() {
|
|||
#[test]
|
||||
fn test_longhands_parse_origin() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
|
||||
let mut parser = Parser::new("1px some-rubbish");
|
||||
let parsed = longhands::parse_origin(&context, &mut parser);
|
||||
|
|
|
@ -53,7 +53,8 @@ fn font_feature_settings_should_parse_properly() {
|
|||
#[test]
|
||||
fn font_feature_settings_should_throw_on_bad_input() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
|
||||
let mut empty = Parser::new("");
|
||||
assert!(font_feature_settings::parse(&context, &mut empty).is_err());
|
||||
|
@ -103,7 +104,8 @@ fn font_weight_keyword_should_preserve_keyword() {
|
|||
use style::properties::longhands::font_weight::SpecifiedValue;
|
||||
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("normal");
|
||||
let result = font_weight::parse(&context, &mut parser);
|
||||
assert_eq!(result.unwrap(), SpecifiedValue::Normal);
|
||||
|
|
|
@ -111,7 +111,8 @@ fn webkit_text_stroke_shorthand_should_parse_properly() {
|
|||
use style::properties::shorthands::_webkit_text_stroke;
|
||||
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
|
||||
let mut parser = Parser::new("thin red");
|
||||
let result = _webkit_text_stroke::parse_value(&context, &mut parser).unwrap();
|
||||
|
@ -132,7 +133,8 @@ fn line_height_should_return_number_on_plain_zero() {
|
|||
use style::properties::longhands::line_height;
|
||||
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("0");
|
||||
let result = line_height::parse(&context, &mut parser);
|
||||
assert_eq!(result.unwrap(), parse_longhand!(line_height, "0"));
|
||||
|
@ -145,7 +147,8 @@ fn line_height_should_return_length_on_length_zero() {
|
|||
use style::properties::longhands::line_height;
|
||||
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("0px");
|
||||
let result = line_height::parse(&context, &mut parser);
|
||||
assert_eq!(result.unwrap(), parse_longhand!(line_height, "0px"));
|
||||
|
|
|
@ -14,7 +14,8 @@ use style::stylesheets::Origin;
|
|||
#[test]
|
||||
fn mask_shorthand_should_parse_all_available_properties_when_specified() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("url(\"http://servo/test.png\") luminance 7px 4px / 70px 50px \
|
||||
repeat-x padding-box border-box subtract");
|
||||
let result = mask::parse_value(&context, &mut parser).unwrap();
|
||||
|
@ -33,7 +34,8 @@ fn mask_shorthand_should_parse_all_available_properties_when_specified() {
|
|||
#[test]
|
||||
fn mask_shorthand_should_parse_when_some_fields_set() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("14px 40px repeat-y");
|
||||
let result = mask::parse_value(&context, &mut parser).unwrap();
|
||||
|
||||
|
@ -62,7 +64,8 @@ fn mask_shorthand_should_parse_when_some_fields_set() {
|
|||
#[test]
|
||||
fn mask_shorthand_should_parse_position_and_size_correctly() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("7px 4px");
|
||||
let result = mask::parse_value(&context, &mut parser).unwrap();
|
||||
|
||||
|
@ -86,7 +89,8 @@ fn mask_shorthand_should_parse_position_and_size_correctly() {
|
|||
#[test]
|
||||
fn mask_shorthand_should_parse_origin_and_clip_correctly() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("padding-box content-box");
|
||||
let result = mask::parse_value(&context, &mut parser).unwrap();
|
||||
|
||||
|
@ -109,7 +113,8 @@ fn mask_shorthand_should_parse_origin_and_clip_correctly() {
|
|||
#[test]
|
||||
fn mask_shorthand_should_parse_mode_everywhere() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new("luminance 7px 4px repeat-x padding-box");
|
||||
assert!(mask::parse_value(&context, &mut parser).is_ok());
|
||||
|
||||
|
|
|
@ -11,7 +11,8 @@ use style::stylesheets::Origin;
|
|||
|
||||
fn parse<T, F: Fn(&ParserContext, &mut Parser) -> Result<T, ()>>(f: F, s: &str) -> Result<T, ()> {
|
||||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new(s);
|
||||
f(&context, &mut parser)
|
||||
}
|
||||
|
@ -24,7 +25,8 @@ macro_rules! assert_roundtrip_with_context {
|
|||
};
|
||||
($fun:expr,$input:expr, $output:expr) => {
|
||||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new($input);
|
||||
let parsed = $fun(&context, &mut parser)
|
||||
.expect(&format!("Failed to parse {}", $input));
|
||||
|
@ -61,7 +63,8 @@ macro_rules! assert_roundtrip {
|
|||
macro_rules! assert_parser_exhausted {
|
||||
($name:ident, $string:expr, $should_exhausted:expr) => {{
|
||||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new($string);
|
||||
let parsed = $name::parse(&context, &mut parser);
|
||||
assert_eq!(parsed.is_ok(), true);
|
||||
|
@ -72,7 +75,8 @@ macro_rules! assert_parser_exhausted {
|
|||
macro_rules! parse_longhand {
|
||||
($name:ident, $s:expr) => {{
|
||||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
$name::parse(&context, &mut Parser::new($s)).unwrap()
|
||||
}};
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@ fn test_outline_style() {
|
|||
// except that 'hidden' is not a legal outline style.
|
||||
|
||||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
let mut parser = Parser::new(r#"hidden"#);
|
||||
let parsed = outline_style::parse(&context, &mut parser);
|
||||
assert!(parsed.is_err());
|
||||
|
|
|
@ -27,7 +27,8 @@ fn test_moz_user_select() {
|
|||
assert_roundtrip_with_context!(_moz_user_select::parse, "-moz-text");
|
||||
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter);
|
||||
|
||||
let mut negative = Parser::new("potato");
|
||||
assert!(_moz_user_select::parse(&context, &mut negative).is_err());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue