mirror of
https://github.com/servo/servo.git
synced 2025-08-11 00:15:32 +01:00
Centralize ParserContext for tests
To simplify adding additional data to `ParserContext`, this moves test usages to a few shared locations, instead of being spread across many tests. MozReview-Commit-ID: 1OahV797eq
This commit is contained in:
parent
f7896fd80b
commit
0936dd24d0
27 changed files with 248 additions and 513 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue