diff --git a/tests/unit/style/lib.rs b/tests/unit/style/lib.rs index 887de470ffac..f6a39d1a656a 100644 --- a/tests/unit/style/lib.rs +++ b/tests/unit/style/lib.rs @@ -32,7 +32,6 @@ mod size_of; mod str; mod stylesheets; mod stylist; -mod value; mod viewport; mod writing_modes { diff --git a/tests/unit/style/parsing/animation.rs b/tests/unit/style/parsing/animation.rs index 0cb0bc62a03c..3db81be64844 100644 --- a/tests/unit/style/parsing/animation.rs +++ b/tests/unit/style/parsing/animation.rs @@ -2,14 +2,11 @@ * 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 media_queries::CSSErrorReporterTest; use parsing::parse; use servo_atoms::Atom; -use style::parser::{Parse, ParserContext}; +use style::parser::Parse; use style::properties::longhands::animation_iteration_count::single_value::computed_value::T as AnimationIterationCount; use style::properties::longhands::animation_name; -use style::stylesheets::{CssRuleType, Origin}; use style_traits::ToCss; #[test] diff --git a/tests/unit/style/parsing/background.rs b/tests/unit/style/parsing/background.rs index d2fea3944c74..dd47e4d1a9ea 100644 --- a/tests/unit/style/parsing/background.rs +++ b/tests/unit/style/parsing/background.rs @@ -2,24 +2,16 @@ * 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 media_queries::CSSErrorReporterTest; -use servo_url::ServoUrl; -use style::parser::ParserContext; +use parsing::parse; use style::properties::longhands::{background_attachment, background_clip, background_color, background_image}; use style::properties::longhands::{background_origin, background_position_x, background_position_y, background_repeat}; use style::properties::longhands::background_size; use style::properties::shorthands::background; -use style::stylesheets::{CssRuleType, Origin}; #[test] fn background_shorthand_should_parse_all_available_properties_when_specified() { - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - 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(); + let input = "url(\"http://servo/test.png\") top center / 200px 200px repeat-x fixed padding-box content-box red"; + let result = parse(background::parse_value, input).unwrap(); assert_eq!(result.background_image, parse_longhand!(background_image, "url(\"http://servo/test.png\")")); assert_eq!(result.background_position_x, parse_longhand!(background_position_x, "center")); @@ -34,43 +26,33 @@ 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 reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new("14px 40px repeat-y"); - let result = background::parse_value(&context, &mut parser).unwrap(); + let result = parse(background::parse_value, "14px 40px repeat-y").unwrap(); assert_eq!(result.background_position_x, parse_longhand!(background_position_x, "14px")); assert_eq!(result.background_position_y, parse_longhand!(background_position_y, "40px")); assert_eq!(result.background_repeat, parse_longhand!(background_repeat, "repeat-y")); - let mut parser = Parser::new("url(\"http://servo/test.png\") repeat blue"); - let result = background::parse_value(&context, &mut parser).unwrap(); + let result = parse(background::parse_value, "url(\"http://servo/test.png\") repeat blue").unwrap(); assert_eq!(result.background_image, parse_longhand!(background_image, "url(\"http://servo/test.png\")")); assert_eq!(result.background_repeat, parse_longhand!(background_repeat, "repeat")); assert_eq!(result.background_color, parse_longhand!(background_color, "blue")); - let mut parser = Parser::new("padding-box"); - let result = background::parse_value(&context, &mut parser).unwrap(); + let result = parse(background::parse_value, "padding-box").unwrap(); assert_eq!(result.background_origin, parse_longhand!(background_origin, "padding-box")); assert_eq!(result.background_clip, parse_longhand!(background_clip, "padding-box")); - let mut parser = Parser::new("url(\"http://servo/test.png\")"); - let result = background::parse_value(&context, &mut parser).unwrap(); + let result = parse(background::parse_value, "url(\"http://servo/test.png\")").unwrap(); assert_eq!(result.background_image, parse_longhand!(background_image, "url(\"http://servo/test.png\")")); } #[test] fn background_shorthand_should_parse_comma_separated_declarations() { - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - 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(); + let input = "url(\"http://servo/test.png\") top left no-repeat, url(\"http://servo/test.png\") \ + center / 100% 100% no-repeat, white"; + let result = parse(background::parse_value, input).unwrap(); assert_eq!(result.background_image, parse_longhand!(background_image, "url(\"http://servo/test.png\"), \ url(\"http://servo/test.png\"), none")); @@ -87,48 +69,35 @@ 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 reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new("7px 4px"); - let result = background::parse_value(&context, &mut parser).unwrap(); + let result = parse(background::parse_value, "7px 4px").unwrap(); assert_eq!(result.background_position_x, parse_longhand!(background_position_x, "7px")); assert_eq!(result.background_position_y, parse_longhand!(background_position_y, "4px")); - let mut parser = Parser::new("7px 4px / 30px 20px"); - let result = background::parse_value(&context, &mut parser).unwrap(); + let result = parse(background::parse_value, "7px 4px / 30px 20px").unwrap(); assert_eq!(result.background_position_x, parse_longhand!(background_position_x, "7px")); assert_eq!(result.background_position_y, parse_longhand!(background_position_y, "4px")); assert_eq!(result.background_size, parse_longhand!(background_size, "30px 20px")); - let mut parser = Parser::new("/ 30px 20px"); - assert!(background::parse_value(&context, &mut parser).is_err()); + assert!(parse(background::parse_value, "/ 30px 20px").is_err()); - let mut parser = Parser::new("repeat-x / 30px 20px"); - assert!(background::parse_value(&context, &mut parser).is_err()); + assert!(parse(background::parse_value, "repeat-x / 30px 20px").is_err()); } #[test] fn background_shorthand_should_parse_origin_and_clip_correctly() { - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new("padding-box content-box"); - let result = background::parse_value(&context, &mut parser).unwrap(); + let result = parse(background::parse_value, "padding-box content-box").unwrap(); assert_eq!(result.background_origin, parse_longhand!(background_origin, "padding-box")); assert_eq!(result.background_clip, parse_longhand!(background_clip, "content-box")); - let mut parser = Parser::new("padding-box padding-box"); - let result = background::parse_value(&context, &mut parser).unwrap(); + let result = parse(background::parse_value, "padding-box padding-box").unwrap(); assert_eq!(result.background_origin, parse_longhand!(background_origin, "padding-box")); assert_eq!(result.background_clip, parse_longhand!(background_clip, "padding-box")); - let mut parser = Parser::new("padding-box"); - let result = background::parse_value(&context, &mut parser).unwrap(); + let result = parse(background::parse_value, "padding-box").unwrap(); assert_eq!(result.background_origin, parse_longhand!(background_origin, "padding-box")); assert_eq!(result.background_clip, parse_longhand!(background_clip, "padding-box")); diff --git a/tests/unit/style/parsing/basic_shape.rs b/tests/unit/style/parsing/basic_shape.rs index 0923499aed9e..ead6b4bb7b09 100644 --- a/tests/unit/style/parsing/basic_shape.rs +++ b/tests/unit/style/parsing/basic_shape.rs @@ -2,11 +2,8 @@ * 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 media_queries::CSSErrorReporterTest; use parsing::parse; -use style::parser::{Parse, ParserContext}; -use style::stylesheets::{CssRuleType, Origin}; +use style::parser::Parse; use style::values::specified::basic_shape::*; use style_traits::ToCss; diff --git a/tests/unit/style/parsing/border.rs b/tests/unit/style/parsing/border.rs index e89d33b2b0ff..e26a4edf4e25 100644 --- a/tests/unit/style/parsing/border.rs +++ b/tests/unit/style/parsing/border.rs @@ -2,24 +2,17 @@ * 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 media_queries::CSSErrorReporterTest; -use servo_url::ServoUrl; -use style::parser::{ParserContext, Parse}; +use parsing::parse; +use style::parser::Parse; use style::properties::longhands::{border_image_outset, border_image_repeat, border_image_slice}; use style::properties::longhands::{border_image_source, border_image_width}; use style::properties::shorthands::border_image; -use style::stylesheets::{CssRuleType, Origin}; use style_traits::ToCss; #[test] fn border_image_shorthand_should_parse_when_all_properties_specified() { - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - 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(); + let input = "linear-gradient(red, blue) 30 30% 45 fill / 20px 40px / 10px round stretch"; + let result = parse(border_image::parse_value, input).unwrap(); assert_eq!(result.border_image_source, parse_longhand!(border_image_source, "linear-gradient(red, blue)")); @@ -31,11 +24,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 reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - 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(); + let input = "linear-gradient(red, blue) 30 30% 45 fill / / 10px round stretch"; + let result = parse(border_image::parse_value, input).unwrap(); assert_eq!(result.border_image_source, parse_longhand!(border_image_source, "linear-gradient(red, blue)")); @@ -47,11 +37,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 reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - 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(); + let input = "linear-gradient(red, blue) 30 30% 45 fill / 20px 40px round"; + let result = parse(border_image::parse_value, input).unwrap(); assert_eq!(result.border_image_source, parse_longhand!(border_image_source, "linear-gradient(red, blue)")); @@ -63,11 +50,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 reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill round"); - let result = border_image::parse_value(&context, &mut parser).unwrap(); + let input = "linear-gradient(red, blue) 30 30% 45 fill round"; + let result = parse(border_image::parse_value, input).unwrap(); assert_eq!(result.border_image_source, parse_longhand!(border_image_source, "linear-gradient(red, blue)")); @@ -79,11 +63,7 @@ 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 reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new("linear-gradient(red, blue)"); - let result = border_image::parse_value(&context, &mut parser).unwrap(); + let result = parse(border_image::parse_value, "linear-gradient(red, blue)").unwrap(); assert_eq!(result.border_image_source, parse_longhand!(border_image_source, "linear-gradient(red, blue)")); @@ -95,41 +75,25 @@ 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 reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new("-1em"); - let result = border_image_outset::parse(&context, &mut parser); + let result = parse(border_image_outset::parse, "-1em"); assert_eq!(result, Err(())); } #[test] fn border_image_outset_should_error_on_negative_number() { - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new("-15"); - let result = border_image_outset::parse(&context, &mut parser); + let result = parse(border_image_outset::parse, "-15"); assert_eq!(result, Err(())); } #[test] fn border_image_outset_should_return_number_on_plain_zero() { - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new("0"); - let result = border_image_outset::parse(&context, &mut parser); + let result = parse(border_image_outset::parse, "0"); assert_eq!(result.unwrap(), parse_longhand!(border_image_outset, "0")); } #[test] fn border_image_outset_should_return_length_on_length_zero() { - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new("0em"); - let result = border_image_outset::parse(&context, &mut parser); + let result = parse(border_image_outset::parse, "0em"); assert_eq!(result.unwrap(), parse_longhand!(border_image_outset, "0em")); } @@ -153,7 +117,7 @@ fn test_border_style() { fn test_border_spacing() { use style::properties::longhands::border_spacing; - assert_parser_exhausted!(border_spacing, "1px rubbish", false); - assert_parser_exhausted!(border_spacing, "1px", true); - assert_parser_exhausted!(border_spacing, "1px 2px", true); + assert_parser_exhausted!(border_spacing::parse, "1px rubbish", false); + assert_parser_exhausted!(border_spacing::parse, "1px", true); + assert_parser_exhausted!(border_spacing::parse, "1px 2px", true); } diff --git a/tests/unit/style/parsing/box_.rs b/tests/unit/style/parsing/box_.rs index 0f7925391a78..c603eb6f48d0 100644 --- a/tests/unit/style/parsing/box_.rs +++ b/tests/unit/style/parsing/box_.rs @@ -2,11 +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 media_queries::CSSErrorReporterTest; use parsing::parse; -use style::parser::ParserContext; -use style::stylesheets::{CssRuleType, Origin}; use style_traits::ToCss; #[test] diff --git a/tests/unit/style/parsing/column.rs b/tests/unit/style/parsing/column.rs index cc8c8532db77..844d6217784a 100644 --- a/tests/unit/style/parsing/column.rs +++ b/tests/unit/style/parsing/column.rs @@ -2,11 +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 media_queries::CSSErrorReporterTest; -use servo_url::ServoUrl; -use style::parser::ParserContext; -use style::stylesheets::{CssRuleType, Origin}; +use parsing::parse; use style_traits::ToCss; #[test] @@ -18,12 +14,7 @@ fn test_column_width() { assert_roundtrip_with_context!(column_width::parse, "2.5em"); assert_roundtrip_with_context!(column_width::parse, "0.3vw"); - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - - let mut negative = Parser::new("-6px"); - assert!(column_width::parse(&context, &mut negative).is_err()); + assert!(parse(column_width::parse, "-6px").is_err()); } #[test] @@ -35,10 +26,5 @@ fn test_column_gap() { assert_roundtrip_with_context!(column_gap::parse, "2.5em"); assert_roundtrip_with_context!(column_gap::parse, "0.3vw"); - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - - let mut negative = Parser::new("-6px"); - assert!(column_gap::parse(&context, &mut negative).is_err()); + assert!(parse(column_gap::parse, "-6px").is_err()); } diff --git a/tests/unit/style/parsing/containment.rs b/tests/unit/style/parsing/containment.rs index d5a7bea97236..d4cffe9f1a5c 100644 --- a/tests/unit/style/parsing/containment.rs +++ b/tests/unit/style/parsing/containment.rs @@ -2,10 +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 media_queries::CSSErrorReporterTest; -use style::parser::ParserContext; -use style::stylesheets::{CssRuleType, Origin}; +use parsing::parse; #[test] fn contain_longhand_should_parse_correctly() { @@ -22,5 +19,5 @@ fn contain_longhand_should_parse_correctly() { assert_eq!(style_paint, contain::STYLE | contain::PAINT); // Assert that the `2px` is not consumed, which would trigger parsing failure in real use - assert_parser_exhausted!(contain, "layout 2px", false); + assert_parser_exhausted!(contain::parse, "layout 2px", false); } diff --git a/tests/unit/style/parsing/effects.rs b/tests/unit/style/parsing/effects.rs index 97c38dad55aa..9fcd03c52354 100644 --- a/tests/unit/style/parsing/effects.rs +++ b/tests/unit/style/parsing/effects.rs @@ -2,13 +2,8 @@ * 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 media_queries::CSSErrorReporterTest; use parsing::parse; -use servo_url::ServoUrl; -use style::parser::ParserContext; use style::properties::longhands::{self, perspective_origin, transform_origin}; -use style::stylesheets::{CssRuleType, Origin}; use style_traits::ToCss; #[test] @@ -37,48 +32,21 @@ fn test_clip() { #[test] fn test_longhands_parse_origin() { - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - - let mut parser = Parser::new("1px some-rubbish"); - let parsed = longhands::parse_origin(&context, &mut parser); - assert!(parsed.is_ok()); - assert_eq!(parser.is_exhausted(), false); - - let mut parser = Parser::new("1px 2px"); - let parsed = longhands::parse_origin(&context, &mut parser); - assert!(parsed.is_ok()); - assert_eq!(parser.is_exhausted(), true); - - let mut parser = Parser::new("center left"); - let parsed = longhands::parse_origin(&context, &mut parser); - assert!(parsed.is_ok()); - assert_eq!(parser.is_exhausted(), true); - - let mut parser = Parser::new("center right"); - let parsed = longhands::parse_origin(&context, &mut parser); - assert!(parsed.is_ok()); - assert_eq!(parser.is_exhausted(), true); - - let mut parser = Parser::new("center right 1px"); - let parsed = longhands::parse_origin(&context, &mut parser); - assert!(parsed.is_ok()); - assert_eq!(parser.is_exhausted(), true); - - let mut parser = Parser::new("1% right"); - let parsed = longhands::parse_origin(&context, &mut parser); - assert!(parsed.is_ok()); - assert_eq!(parser.is_exhausted(), false); + assert_parser_exhausted!(longhands::parse_origin, "1px some-rubbish", false); + assert_parser_exhausted!(longhands::parse_origin, "1px 2px", true); + assert_parser_exhausted!(longhands::parse_origin, "center left", true); + assert_parser_exhausted!(longhands::parse_origin, "center right", true); + assert_parser_exhausted!(longhands::parse_origin, "center right 1px", true); + assert_parser_exhausted!(longhands::parse_origin, "1% right", false); } #[test] fn test_effects_parser_exhaustion() { - assert_parser_exhausted!(perspective_origin, "1px 1px", true); - assert_parser_exhausted!(transform_origin, "1px 1px", true); + assert_parser_exhausted!(perspective_origin::parse, "1px 1px", true); + assert_parser_exhausted!(transform_origin::parse, "1px 1px", true); - assert_parser_exhausted!(perspective_origin, "1px some-rubbish", false); - assert_parser_exhausted!(transform_origin, "1px some-rubbish", false); + assert_parser_exhausted!(perspective_origin::parse, "1px some-rubbish", false); + assert_parser_exhausted!(transform_origin::parse, "1px some-rubbish", false); } #[test] diff --git a/tests/unit/style/parsing/font.rs b/tests/unit/style/parsing/font.rs index 19aa0f121720..cdb649614839 100644 --- a/tests/unit/style/parsing/font.rs +++ b/tests/unit/style/parsing/font.rs @@ -2,14 +2,10 @@ * 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 media_queries::CSSErrorReporterTest; -use servo_url::ServoUrl; -use style::parser::ParserContext; +use parsing::parse; use style::properties::longhands::{font_feature_settings, font_weight}; use style::properties::longhands::font_feature_settings::computed_value; use style::properties::longhands::font_feature_settings::computed_value::FeatureTagValue; -use style::stylesheets::{CssRuleType, Origin}; use style_traits::ToCss; #[test] @@ -52,21 +48,10 @@ 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 reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - - let mut empty = Parser::new(""); - assert!(font_feature_settings::parse(&context, &mut empty).is_err()); - - let mut negative = Parser::new("\"abcd\" -1"); - assert!(font_feature_settings::parse(&context, &mut negative).is_err()); - - let mut short_tag = Parser::new("\"abc\""); - assert!(font_feature_settings::parse(&context, &mut short_tag).is_err()); - - let mut illegal_tag = Parser::new("\"abcó\""); - assert!(font_feature_settings::parse(&context, &mut illegal_tag).is_err()); + assert!(parse(font_feature_settings::parse, "").is_err()); + assert!(parse(font_feature_settings::parse, "\"abcd\" -1").is_err()); + assert!(parse(font_feature_settings::parse, "\"abc\"").is_err()); + assert!(parse(font_feature_settings::parse, "\"abcó\"").is_err()); } #[test] @@ -103,16 +88,11 @@ fn font_language_override_should_parse_properly() { fn font_weight_keyword_should_preserve_keyword() { use style::properties::longhands::font_weight::SpecifiedValue; - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new("normal"); - let result = font_weight::parse(&context, &mut parser); - assert_eq!(result.unwrap(), SpecifiedValue::Normal); + let result = parse(font_weight::parse, "normal").unwrap(); + assert_eq!(result, SpecifiedValue::Normal); - let mut parser = Parser::new("bold"); - let result = font_weight::parse(&context, &mut parser); - assert_eq!(result.unwrap(), SpecifiedValue::Bold); + let result = parse(font_weight::parse, "bold").unwrap(); + assert_eq!(result, SpecifiedValue::Bold); } #[test] diff --git a/tests/unit/style/parsing/image.rs b/tests/unit/style/parsing/image.rs index 4859abf41df7..78a6b04eed9b 100644 --- a/tests/unit/style/parsing/image.rs +++ b/tests/unit/style/parsing/image.rs @@ -2,15 +2,12 @@ * 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 euclid::size::TypedSize2D; -use media_queries::CSSErrorReporterTest; +use parsing::parse; use std::f32::consts::PI; use style::font_metrics::ServoMetricsProvider; use style::media_queries::{Device, MediaType}; -use style::parser::ParserContext; use style::properties::ComputedValues; -use style::stylesheets::{CssRuleType, Origin}; use style::values::computed; use style::values::computed::{Angle, Context, ToComputedValue}; use style::values::specified; diff --git a/tests/unit/style/parsing/inherited_box.rs b/tests/unit/style/parsing/inherited_box.rs index 8eb0cd8d48d8..e720035c2e61 100644 --- a/tests/unit/style/parsing/inherited_box.rs +++ b/tests/unit/style/parsing/inherited_box.rs @@ -2,10 +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 media_queries::CSSErrorReporterTest; -use style::parser::ParserContext; -use style::stylesheets::{CssRuleType, Origin}; +use parsing::parse; #[test] fn image_orientation_longhand_should_parse_properly() { diff --git a/tests/unit/style/parsing/inherited_text.rs b/tests/unit/style/parsing/inherited_text.rs index ce25252b25dd..af0ec0ee5d1d 100644 --- a/tests/unit/style/parsing/inherited_text.rs +++ b/tests/unit/style/parsing/inherited_text.rs @@ -2,10 +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 media_queries::CSSErrorReporterTest; -use style::parser::ParserContext; -use style::stylesheets::{CssRuleType, Origin}; +use parsing::parse; #[test] fn negative_letter_spacing_should_parse_properly() { @@ -104,52 +101,32 @@ fn test_text_emphasis_position() { #[test] fn webkit_text_stroke_shorthand_should_parse_properly() { - use media_queries::CSSErrorReporterTest; - use servo_url::ServoUrl; use style::properties::longhands::_webkit_text_stroke_color; use style::properties::longhands::_webkit_text_stroke_width; use style::properties::shorthands::_webkit_text_stroke; - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - - let mut parser = Parser::new("thin red"); - let result = _webkit_text_stroke::parse_value(&context, &mut parser).unwrap(); + let result = parse(_webkit_text_stroke::parse_value, "thin red").unwrap(); assert_eq!(result._webkit_text_stroke_color, parse_longhand!(_webkit_text_stroke_color, "red")); assert_eq!(result._webkit_text_stroke_width, parse_longhand!(_webkit_text_stroke_width, "thin")); // ensure its no longer sensitive to order - let mut parser = Parser::new("red thin"); - let result = _webkit_text_stroke::parse_value(&context, &mut parser).unwrap(); + let result = parse(_webkit_text_stroke::parse_value, "red thin").unwrap(); assert_eq!(result._webkit_text_stroke_color, parse_longhand!(_webkit_text_stroke_color, "red")); assert_eq!(result._webkit_text_stroke_width, parse_longhand!(_webkit_text_stroke_width, "thin")); } #[test] fn line_height_should_return_number_on_plain_zero() { - use media_queries::CSSErrorReporterTest; - use servo_url::ServoUrl; use style::properties::longhands::line_height; - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new("0"); - let result = line_height::parse(&context, &mut parser); - assert_eq!(result.unwrap(), parse_longhand!(line_height, "0")); + let result = parse(line_height::parse, "0").unwrap(); + assert_eq!(result, parse_longhand!(line_height, "0")); } #[test] fn line_height_should_return_length_on_length_zero() { - use media_queries::CSSErrorReporterTest; - use servo_url::ServoUrl; use style::properties::longhands::line_height; - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new("0px"); - let result = line_height::parse(&context, &mut parser); - assert_eq!(result.unwrap(), parse_longhand!(line_height, "0px")); + let result = parse(line_height::parse, "0px").unwrap(); + assert_eq!(result, parse_longhand!(line_height, "0px")); } diff --git a/tests/unit/style/parsing/mask.rs b/tests/unit/style/parsing/mask.rs index b3f3912d7c95..c027e9610839 100644 --- a/tests/unit/style/parsing/mask.rs +++ b/tests/unit/style/parsing/mask.rs @@ -2,23 +2,15 @@ * 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 media_queries::CSSErrorReporterTest; -use servo_url::ServoUrl; -use style::parser::ParserContext; +use parsing::parse; use style::properties::longhands::{mask_clip, mask_composite, mask_image, mask_mode}; use style::properties::longhands::{mask_origin, mask_position_x, mask_position_y, mask_repeat, mask_size}; use style::properties::shorthands::mask; -use style::stylesheets::{CssRuleType, Origin}; #[test] fn mask_shorthand_should_parse_all_available_properties_when_specified() { - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - 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(); + let input = "url(\"http://servo/test.png\") luminance 7px 4px / 70px 50px repeat-x padding-box border-box subtract"; + let result = parse(mask::parse_value, input).unwrap(); assert_eq!(result.mask_image, parse_longhand!(mask_image, "url(\"http://servo/test.png\")")); assert_eq!(result.mask_mode, parse_longhand!(mask_mode, "luminance")); @@ -33,78 +25,58 @@ 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 reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new("14px 40px repeat-y"); - let result = mask::parse_value(&context, &mut parser).unwrap(); + let result = parse(mask::parse_value, "14px 40px repeat-y").unwrap(); assert_eq!(result.mask_position_x, parse_longhand!(mask_position_x, "14px")); assert_eq!(result.mask_position_y, parse_longhand!(mask_position_y, "40px")); assert_eq!(result.mask_repeat, parse_longhand!(mask_repeat, "repeat-y")); - let mut parser = Parser::new("url(\"http://servo/test.png\") repeat add"); - let result = mask::parse_value(&context, &mut parser).unwrap(); + let result = parse(mask::parse_value, "url(\"http://servo/test.png\") repeat add").unwrap(); assert_eq!(result.mask_image, parse_longhand!(mask_image, "url(\"http://servo/test.png\")")); assert_eq!(result.mask_repeat, parse_longhand!(mask_repeat, "repeat")); assert_eq!(result.mask_composite, parse_longhand!(mask_composite, "add")); - let mut parser = Parser::new("intersect"); - let result = mask::parse_value(&context, &mut parser).unwrap(); + let result = parse(mask::parse_value, "intersect").unwrap(); assert_eq!(result.mask_composite, parse_longhand!(mask_composite, "intersect")); - let mut parser = Parser::new("url(\"http://servo/test.png\")"); - let result = mask::parse_value(&context, &mut parser).unwrap(); + let result = parse(mask::parse_value, "url(\"http://servo/test.png\")").unwrap(); assert_eq!(result.mask_image, parse_longhand!(mask_image, "url(\"http://servo/test.png\")")); } #[test] fn mask_shorthand_should_parse_position_and_size_correctly() { - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new("7px 4px"); - let result = mask::parse_value(&context, &mut parser).unwrap(); + let result = parse(mask::parse_value, "7px 4px").unwrap(); assert_eq!(result.mask_position_x, parse_longhand!(mask_position_x, "7px")); assert_eq!(result.mask_position_y, parse_longhand!(mask_position_y, "4px")); - let mut parser = Parser::new("7px 4px / 30px 20px"); - let result = mask::parse_value(&context, &mut parser).unwrap(); + let result = parse(mask::parse_value, "7px 4px / 30px 20px").unwrap(); assert_eq!(result.mask_position_x, parse_longhand!(mask_position_x, "7px")); assert_eq!(result.mask_position_y, parse_longhand!(mask_position_y, "4px")); assert_eq!(result.mask_size, parse_longhand!(mask_size, "30px 20px")); - let mut parser = Parser::new("/ 30px 20px"); - assert!(mask::parse_value(&context, &mut parser).is_err()); + assert!(parse(mask::parse_value, "/ 30px 20px").is_err()); - let mut parser = Parser::new("match-source repeat-x / 30px 20px"); - assert!(mask::parse_value(&context, &mut parser).is_err()); + assert!(parse(mask::parse_value, "match-source repeat-x / 30px 20px").is_err()); } #[test] fn mask_shorthand_should_parse_origin_and_clip_correctly() { - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new("padding-box content-box"); - let result = mask::parse_value(&context, &mut parser).unwrap(); + let result = parse(mask::parse_value, "padding-box content-box").unwrap(); assert_eq!(result.mask_origin, parse_longhand!(mask_origin, "padding-box")); assert_eq!(result.mask_clip, parse_longhand!(mask_clip, "content-box")); - let mut parser = Parser::new("padding-box padding-box"); - let result = mask::parse_value(&context, &mut parser).unwrap(); + let result = parse(mask::parse_value, "padding-box padding-box").unwrap(); assert_eq!(result.mask_origin, parse_longhand!(mask_origin, "padding-box")); assert_eq!(result.mask_clip, parse_longhand!(mask_clip, "padding-box")); - let mut parser = Parser::new("padding-box"); - let result = mask::parse_value(&context, &mut parser).unwrap(); + let result = parse(mask::parse_value, "padding-box").unwrap(); assert_eq!(result.mask_origin, parse_longhand!(mask_origin, "padding-box")); assert_eq!(result.mask_clip, parse_longhand!(mask_clip, "padding-box")); @@ -112,14 +84,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 reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new("luminance 7px 4px repeat-x padding-box"); - assert!(mask::parse_value(&context, &mut parser).is_ok()); - - let mut parser = Parser::new("alpha"); - assert!(mask::parse_value(&context, &mut parser).is_ok()); + assert!(parse(mask::parse_value, "luminance 7px 4px repeat-x padding-box").is_ok()); + assert!(parse(mask::parse_value, "alpha").is_ok()); } #[test] @@ -153,23 +119,13 @@ fn mask_repeat_should_parse_shorthand_correctly() { fn mask_repeat_should_parse_longhand_correctly() { use style::properties::longhands::mask_repeat::single_value::{RepeatKeyword, SpecifiedValue}; - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - // repeat-x is not available in longhand form. - let mut parser = Parser::new("repeat-x no-repeat"); - assert!(mask_repeat::parse(&context, &mut parser).is_err()); - - let mut parser = Parser::new("no-repeat repeat-x"); - assert!(mask_repeat::parse(&context, &mut parser).is_err()); + assert!(parse(mask_repeat::parse, "repeat-x no-repeat").is_err()); + assert!(parse(mask_repeat::parse, "no-repeat repeat-x").is_err()); // repeat-y is not available in longhand form. - let mut parser = Parser::new("repeat-y no-repeat"); - assert!(mask_repeat::parse(&context, &mut parser).is_err()); - - let mut parser = Parser::new("no-repeat repeat-y"); - assert!(mask_repeat::parse(&context, &mut parser).is_err()); + assert!(parse(mask_repeat::parse, "repeat-y no-repeat").is_err()); + assert!(parse(mask_repeat::parse, "no-repeat repeat-y").is_err()); // Longhand form supports two directions. let no_repeat_and_round = parse_longhand!(mask_repeat, "no-repeat round"); @@ -178,8 +134,7 @@ fn mask_repeat_should_parse_longhand_correctly() { Some(RepeatKeyword::Round))])); // Not three directions. - let mut parser = Parser::new("repeat no-repeat round"); - assert!(mask_repeat::parse(&context, &mut parser).is_err()); + assert!(parse(mask_repeat::parse, "repeat no-repeat round").is_err()); // Multiple values with mixed shortform and longform should parse. let multiple = parse_longhand!(mask_repeat, "repeat, no-repeat round"); diff --git a/tests/unit/style/parsing/mod.rs b/tests/unit/style/parsing/mod.rs index b6da9a138d65..48a08ff10738 100644 --- a/tests/unit/style/parsing/mod.rs +++ b/tests/unit/style/parsing/mod.rs @@ -23,29 +23,30 @@ macro_rules! assert_roundtrip_with_context { ($fun:expr, $string:expr) => { assert_roundtrip_with_context!($fun, $string, $string); }; - ($fun:expr,$input:expr, $output:expr) => { - let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new($input); - let parsed = $fun(&context, &mut parser) - .expect(&format!("Failed to parse {}", $input)); - let serialized = ToCss::to_css_string(&parsed); - assert_eq!(serialized, $output); + ($fun:expr, $input:expr, $output:expr) => {{ + let serialized = parse(|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(); - let mut parser = Parser::new(&serialized); - let re_parsed = $fun(&context, &mut parser) - .expect(&format!("Failed to parse serialization {}", $input)); - let re_serialized = ToCss::to_css_string(&re_parsed); - assert_eq!(serialized, re_serialized); - } + parse(|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() + }} } macro_rules! assert_roundtrip { ($fun:expr, $string:expr) => { assert_roundtrip!($fun, $string, $string); }; - ($fun:expr,$input:expr, $output:expr) => { + ($fun:expr, $input:expr, $output:expr) => { let mut parser = Parser::new($input); let parsed = $fun(&mut parser) .expect(&format!("Failed to parse {}", $input)); @@ -56,29 +57,25 @@ macro_rules! assert_roundtrip { let re_parsed = $fun(&mut parser) .expect(&format!("Failed to parse serialization {}", $input)); let re_serialized = ToCss::to_css_string(&re_parsed); - assert_eq!(serialized, re_serialized); + assert_eq!(serialized, re_serialized) } } macro_rules! assert_parser_exhausted { - ($name:ident, $string:expr, $should_exhausted:expr) => {{ - let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new($string); - let parsed = $name::parse(&context, &mut parser); - assert_eq!(parsed.is_ok(), true); - assert_eq!(parser.is_exhausted(), $should_exhausted); + ($fun:expr, $string:expr, $should_exhausted:expr) => {{ + parse(|context, input| { + let parsed = $fun(context, input); + assert_eq!(parsed.is_ok(), true); + assert_eq!(input.is_exhausted(), $should_exhausted); + Ok(()) + }, $string).unwrap() }} } macro_rules! parse_longhand { - ($name:ident, $s:expr) => {{ - let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - $name::parse(&context, &mut Parser::new($s)).unwrap() - }}; + ($name:ident, $s:expr) => { + parse($name::parse, $s).unwrap() + }; } mod animation; @@ -103,3 +100,4 @@ mod text; mod text_overflow; mod transition_timing_function; mod ui; +mod value; diff --git a/tests/unit/style/parsing/outline.rs b/tests/unit/style/parsing/outline.rs index 787d4172055c..70123c8227db 100644 --- a/tests/unit/style/parsing/outline.rs +++ b/tests/unit/style/parsing/outline.rs @@ -2,10 +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 media_queries::CSSErrorReporterTest; -use style::parser::ParserContext; -use style::stylesheets::{CssRuleType, Origin}; +use parsing::parse; use style_traits::ToCss; #[test] @@ -23,16 +20,7 @@ fn test_outline_style() { assert_roundtrip_with_context!(outline_style::parse, r#"inset"#); assert_roundtrip_with_context!(outline_style::parse, r#"outset"#); - { - // The outline-style property accepts the same values as border-style, - // except that 'hidden' is not a legal outline style. - - let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new(r#"hidden"#); - let parsed = outline_style::parse(&context, &mut parser); - assert!(parsed.is_err()); - }; - + // The outline-style property accepts the same values as border-style, + // except that 'hidden' is not a legal outline style. + assert!(parse(outline_style::parse, r#"hidden"#).is_err()); } diff --git a/tests/unit/style/parsing/position.rs b/tests/unit/style/parsing/position.rs index 04da426ded82..e5e8aa6379dc 100644 --- a/tests/unit/style/parsing/position.rs +++ b/tests/unit/style/parsing/position.rs @@ -2,11 +2,8 @@ * 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 media_queries::CSSErrorReporterTest; use parsing::parse; -use style::parser::{Parse, ParserContext}; -use style::stylesheets::{CssRuleType, Origin}; +use style::parser::Parse; use style::values::specified::position::*; use style_traits::ToCss; diff --git a/tests/unit/style/parsing/selectors.rs b/tests/unit/style/parsing/selectors.rs index 24ccc11d546e..08c8217d8fab 100644 --- a/tests/unit/style/parsing/selectors.rs +++ b/tests/unit/style/parsing/selectors.rs @@ -3,13 +3,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use cssparser::{Parser, ToCss}; -use media_queries::CSSErrorReporterTest; use selectors::parser::SelectorList; -use style::parser::ParserContext; use style::selector_parser::{SelectorImpl, SelectorParser}; -use style::stylesheets::{CssRuleType, Origin, Namespaces}; +use style::stylesheets::{Origin, Namespaces}; -fn parse(_context: &ParserContext, input: &mut Parser) -> Result, ()> { +fn parse_selector(input: &mut Parser) -> Result, ()> { let mut ns = Namespaces::default(); ns.prefixes.insert("svg".into(), ns!(svg)); let parser = SelectorParser { @@ -21,8 +19,8 @@ fn parse(_context: &ParserContext, input: &mut Parser) -> Result Result { + parse(|context, input| CalcLengthOrPercentage::parse(context, input, unit), text) + } + assert_eq!(parse_value("1", CalcUnit::Length), Err(())); + assert_eq!(parse_value("1", CalcUnit::LengthOrPercentage), Err(())); + assert_eq!(parse_value("1", CalcUnit::Angle), Err(())); + assert_eq!(parse_value("1", CalcUnit::Time), Err(())); + assert_eq!(parse_value("1px + 1", CalcUnit::Length), Err(())); + assert_eq!(parse_value("1em + 1", CalcUnit::Length), Err(())); + assert_eq!(parse_value("1px + 1", CalcUnit::LengthOrPercentage), Err(())); + assert_eq!(parse_value("1% + 1", CalcUnit::LengthOrPercentage), Err(())); + assert_eq!(parse_value("1rad + 1", CalcUnit::Angle), Err(())); + assert_eq!(parse_value("1deg + 1", CalcUnit::Angle), Err(())); + assert_eq!(parse_value("1s + 1", CalcUnit::Time), Err(())); +} diff --git a/tests/unit/style/properties/background.rs b/tests/unit/style/properties/background.rs index c83286c10c82..a45211ce8c96 100644 --- a/tests/unit/style/properties/background.rs +++ b/tests/unit/style/properties/background.rs @@ -2,19 +2,10 @@ * 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 media_queries::CSSErrorReporterTest; -use style::parser::ParserContext; +use properties::parse; use style::properties::longhands::background_size; -use style::stylesheets::{CssRuleType, Origin}; #[test] fn background_size_should_reject_negative_values() { - let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - - let parse_result = background_size::parse(&context, &mut Parser::new("-40% -40%")); - - assert_eq!(parse_result.is_err(), true); + assert!(parse(background_size::parse, "-40% -40%").is_err()); } diff --git a/tests/unit/style/properties/mod.rs b/tests/unit/style/properties/mod.rs index 68713440b45a..8836d96d0d04 100644 --- a/tests/unit/style/properties/mod.rs +++ b/tests/unit/style/properties/mod.rs @@ -2,6 +2,42 @@ * 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 media_queries::CSSErrorReporterTest; +use style::parser::ParserContext; +use style::stylesheets::{CssRuleType, Origin}; + +fn parse Result>(f: F, s: &str) -> Result { + let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); + let reporter = CSSErrorReporterTest; + let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); + let mut parser = Parser::new(s); + f(&context, &mut parser) +} + +macro_rules! assert_roundtrip_with_context { + ($fun:expr, $string:expr) => { + assert_roundtrip_with_context!($fun, $string, $string); + }; + ($fun:expr, $input:expr, $output:expr) => {{ + let serialized = parse(|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(); + + parse(|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() + }} +} + mod background; mod scaffolding; mod serialization; diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index 04dffa1aa5a1..3de30df2a97e 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -2,15 +2,11 @@ * 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 media_queries::CSSErrorReporterTest; -use servo_url::ServoUrl; +use properties::parse; use style::computed_values::display::T::inline_block; -use style::parser::ParserContext; -use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, Importance, PropertyId}; +use style::properties::{PropertyDeclaration, Importance, PropertyId}; use style::properties::longhands::outline_color::computed_value::T as ComputedColor; use style::properties::parse_property_declaration_list; -use style::stylesheets::{CssRuleType, Origin}; use style::values::{RGBA, Auto}; use style::values::specified::{BorderStyle, BorderWidth, CSSColor, Length, NoCalcLength}; use style::values::specified::{LengthOrPercentage, LengthOrPercentageOrAuto, LengthOrPercentageOrAutoOrContent}; @@ -18,14 +14,6 @@ use style::values::specified::url::SpecifiedUrl; use style_traits::ToCss; use stylesheets::block_from; -fn parse_declaration_block(css_properties: &str) -> PropertyDeclarationBlock { - let url = ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new(css_properties); - parse_property_declaration_list(&context, &mut parser) -} - #[test] fn property_declaration_block_should_serialize_correctly() { use style::properties::longhands::overflow_x::SpecifiedValue as OverflowXValue; @@ -626,7 +614,7 @@ mod shorthand_serialization { font-language-override: normal; \ font-kerning: none"; - let block = parse_declaration_block(block_text); + let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let mut s = String::new(); let id = PropertyId::parse("font".into()).unwrap(); @@ -651,7 +639,7 @@ mod shorthand_serialization { font-variant-position: normal; \ font-language-override: normal;"; - let block = parse_declaration_block(block_text); + let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let serialization = block.to_css_string(); @@ -675,7 +663,8 @@ mod shorthand_serialization { background-position-y: 4px; \ background-origin: border-box; \ background-clip: padding-box;"; - let block = parse_declaration_block(block_text); + + let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let serialization = block.to_css_string(); @@ -698,7 +687,8 @@ mod shorthand_serialization { background-position-y: 4px; \ background-origin: padding-box; \ background-clip: padding-box;"; - let block = parse_declaration_block(block_text); + + let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let serialization = block.to_css_string(); @@ -721,7 +711,8 @@ mod shorthand_serialization { background-position-y: 4px, 40px; \ background-origin: border-box, padding-box; \ background-clip: padding-box, padding-box;"; - let block = parse_declaration_block(block_text); + + let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let serialization = block.to_css_string(); @@ -751,7 +742,8 @@ mod shorthand_serialization { background-position: 7px 4px, 5px 6px; \ background-origin: border-box; \ background-clip: padding-box, padding-box;"; - let block = parse_declaration_block(block_text); + + let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let serialization = block.to_css_string(); @@ -909,7 +901,7 @@ mod shorthand_serialization { #[test] fn serialize_mask_position_with_multiple_values() { let block_text = "mask-position: 1px 2px, 4px 3px;"; - let block = parse_declaration_block(block_text); + let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let serialization = block.to_css_string(); assert_eq!(serialization, block_text); } @@ -967,22 +959,9 @@ mod shorthand_serialization { #[test] fn should_serialize_none_correctly() { - use cssparser::Parser; - use media_queries::CSSErrorReporterTest; - use style::parser::ParserContext; use style::properties::longhands::transform; - use style::stylesheets::Origin; - let mut s = String::new(); - let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - - let parsed = transform::parse(&context, &mut Parser::new("none")).unwrap(); - let try_serialize = parsed.to_css(&mut s); - - assert_eq!(try_serialize.is_ok(), true); - assert_eq!(s, "none"); + assert_roundtrip_with_context!(transform::parse, "none"); } #[inline(always)] @@ -1031,22 +1010,9 @@ mod shorthand_serialization { #[test] fn should_serialize_none_correctly() { - use cssparser::Parser; - use media_queries::CSSErrorReporterTest; - use style::parser::ParserContext; use style::properties::longhands::quotes; - use style::stylesheets::Origin; - - let mut s = String::new(); - let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let parsed = quotes::parse(&context, &mut Parser::new("none")).unwrap(); - let try_serialize = parsed.to_css(&mut s); - - assert_eq!(try_serialize.is_ok(), true); - assert_eq!(s, "none"); + assert_roundtrip_with_context!(quotes::parse, "none"); } } @@ -1055,7 +1021,7 @@ mod shorthand_serialization { #[test] fn serialize_single_animation() { - let block = parse_declaration_block("\ + let block_text = "\ animation-name: bounce;\ animation-duration: 1s;\ animation-timing-function: ease-in;\ @@ -1063,7 +1029,9 @@ mod shorthand_serialization { animation-direction: normal;\ animation-fill-mode: forwards;\ animation-iteration-count: infinite;\ - animation-play-state: paused;"); + animation-play-state: paused;"; + + let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let serialization = block.to_css_string(); @@ -1072,7 +1040,7 @@ mod shorthand_serialization { #[test] fn serialize_multiple_animations() { - let block = parse_declaration_block("\ + let block_text = "\ animation-name: bounce, roll;\ animation-duration: 1s, 0.2s;\ animation-timing-function: ease-in, linear;\ @@ -1080,7 +1048,9 @@ mod shorthand_serialization { animation-direction: normal, reverse;\ animation-fill-mode: forwards, backwards;\ animation-iteration-count: infinite, 2;\ - animation-play-state: paused, running;"); + animation-play-state: paused, running;"; + + let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let serialization = block.to_css_string(); @@ -1105,7 +1075,8 @@ mod shorthand_serialization { animation-fill-mode: forwards, backwards; \ animation-iteration-count: infinite, 2; \ animation-play-state: paused, running;"; - let block = parse_declaration_block(block_text); + + let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let serialization = block.to_css_string(); @@ -1121,7 +1092,8 @@ mod shorthand_serialization { animation-fill-mode: forwards, backwards; \ animation-iteration-count: infinite, 2; \ animation-play-state: paused, running;"; - let block = parse_declaration_block(block_text); + + let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let serialization = block.to_css_string(); @@ -1138,7 +1110,8 @@ mod shorthand_serialization { transition-duration: 3s; \ transition-delay: 4s; \ transition-timing-function: cubic-bezier(0.2, 5, 0.5, 2);"; - let block = parse_declaration_block(block_text); + + let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let serialization = block.to_css_string(); @@ -1151,7 +1124,8 @@ mod shorthand_serialization { transition-duration: 3s, 2s; \ transition-delay: 4s, 5s; \ transition-timing-function: cubic-bezier(0.2, 5, 0.5, 2), ease;"; - let block = parse_declaration_block(block_text); + + let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let serialization = block.to_css_string(); @@ -1172,7 +1146,8 @@ mod shorthand_serialization { transition-duration: 3s, 2s, 4s; \ transition-delay: 4s, 5s; \ transition-timing-function: cubic-bezier(0.2, 5, 0.5, 2), ease;"; - let block = parse_declaration_block(block_text); + + let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let serialization = block.to_css_string(); @@ -1185,7 +1160,7 @@ mod shorthand_serialization { #[test] fn css_wide_keywords_should_be_parsed() { let block_text = "--a:inherit;"; - let block = parse_declaration_block(block_text); + let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let serialization = block.to_css_string(); assert_eq!(serialization, "--a: inherit;"); @@ -1194,7 +1169,7 @@ mod shorthand_serialization { #[test] fn non_keyword_custom_property_should_be_unparsed() { let block_text = "--main-color: #06c;"; - let block = parse_declaration_block(block_text); + let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let serialization = block.to_css_string(); assert_eq!(serialization, block_text); @@ -1214,7 +1189,7 @@ mod shorthand_serialization { let shadow_decl = BoxShadow(vec![shadow_val]); properties.push(PropertyDeclaration:: BoxShadow(shadow_decl)); let shadow_css = "box-shadow: 1px 2px 3px 4px;"; - let shadow = parse_declaration_block(shadow_css); + let shadow = parse(|c, i| Ok(parse_property_declaration_list(c, i)), shadow_css).unwrap(); assert_eq!(shadow.to_css_string(), shadow_css); } diff --git a/tests/unit/style/value.rs b/tests/unit/style/value.rs deleted file mode 100644 index d81d987a3cc3..000000000000 --- a/tests/unit/style/value.rs +++ /dev/null @@ -1,42 +0,0 @@ -/* 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 app_units::Au; -use cssparser::Parser; -use media_queries::CSSErrorReporterTest; -use style::parser::ParserContext; -use style::stylesheets::{CssRuleType, Origin}; -use style::values::HasViewportPercentage; -use style::values::specified::{AbsoluteLength, ViewportPercentageLength, NoCalcLength}; -use style::values::specified::length::{CalcLengthOrPercentage, CalcUnit}; - -#[test] -fn length_has_viewport_percentage() { - let l = NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(100.)); - assert!(l.has_viewport_percentage()); - let l = NoCalcLength::Absolute(AbsoluteLength::Px(Au(100).to_f32_px())); - assert!(!l.has_viewport_percentage()); -} - -#[test] -fn calc_top_level_number_with_unit() { - fn parse(text: &str, unit: CalcUnit) -> Result { - let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); - let reporter = CSSErrorReporterTest; - let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style)); - let mut parser = Parser::new(text); - CalcLengthOrPercentage::parse(&context, &mut parser, unit) - } - assert_eq!(parse("1", CalcUnit::Length), Err(())); - assert_eq!(parse("1", CalcUnit::LengthOrPercentage), Err(())); - assert_eq!(parse("1", CalcUnit::Angle), Err(())); - assert_eq!(parse("1", CalcUnit::Time), Err(())); - assert_eq!(parse("1px + 1", CalcUnit::Length), Err(())); - assert_eq!(parse("1em + 1", CalcUnit::Length), Err(())); - assert_eq!(parse("1px + 1", CalcUnit::LengthOrPercentage), Err(())); - assert_eq!(parse("1% + 1", CalcUnit::LengthOrPercentage), Err(())); - assert_eq!(parse("1rad + 1", CalcUnit::Angle), Err(())); - assert_eq!(parse("1deg + 1", CalcUnit::Angle), Err(())); - assert_eq!(parse("1s + 1", CalcUnit::Time), Err(())); -}