Auto merge of #15278 - atheed:zero-parsing, r=Wafflespeanut

Parsing "0" as Number for line-height and border-image-outset

Fixes #15171 by correctly parsing `0` as `0` (rather than as `0px`, as was the case earlier) for the `line-height` and `border-image-outset` CSS properties. Wrote unit tests for both; `./mach test-unit -p style` passes all tests.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #15171

<!-- Either: -->
- [X] There are tests for these changes.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15278)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-01-28 22:18:44 -08:00 committed by GitHub
commit dfcfc1d2c1
4 changed files with 69 additions and 18 deletions

View file

@ -104,3 +104,21 @@ fn border_image_outset_should_error_on_negative_number() {
let result = border_image_outset::parse(&context, &mut parser);
assert_eq!(result, Err(()));
}
#[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 mut parser = Parser::new("0");
let result = border_image_outset::parse(&context, &mut parser);
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 context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
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"));
}

View file

@ -102,3 +102,29 @@ fn webkit_text_stroke_shorthand_should_parse_properly() {
assert_eq!(result._webkit_text_stroke_color.unwrap(), parse_longhand!(_webkit_text_stroke_color, "red"));
assert_eq!(result._webkit_text_stroke_width.unwrap(), 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 context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("0");
let result = line_height::parse(&context, &mut parser);
assert_eq!(result.unwrap(), 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 context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("0px");
let result = line_height::parse(&context, &mut parser);
assert_eq!(result.unwrap(), parse_longhand!(line_height, "0px"));
}