Auto merge of #8526 - frewsxcv:parse-length, r=eefriedman

Fix parse_length 0 values, implement <hr> 'width'

Follow-up to https://github.com/servo/servo/issues/8424

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8526)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-11-15 03:30:46 +05:30
commit 3ef0a9a79d
13 changed files with 117 additions and 147 deletions

View file

@ -16,6 +16,7 @@ path = "../../../components/util"
path = "../../../components/plugins"
[dependencies]
app_units = {version = "0.1", features = ["plugins"]}
libc = "0.1"
euclid = {version = "0.3", features = ["plugins"]}

View file

@ -7,6 +7,7 @@
#![feature(alloc)]
extern crate alloc;
extern crate app_units;
extern crate euclid;
extern crate libc;
extern crate util;

View file

@ -2,9 +2,26 @@
* 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 util::str::{search_index, split_html_space_chars, str_join};
use app_units::Au;
use util::str::LengthOrPercentageOrAuto;
use util::str::{parse_length, search_index, split_html_space_chars, str_join};
#[test]
pub fn test_parse_length() {
fn check(input: &str, expected: LengthOrPercentageOrAuto) {
let parsed = parse_length(input);
assert_eq!(parsed, expected);
}
check("0", LengthOrPercentageOrAuto::Length(Au::from_px(0)));
check("0.000%", LengthOrPercentageOrAuto::Percentage(0.0));
check("+5.82%", LengthOrPercentageOrAuto::Percentage(0.0582));
check("5.82", LengthOrPercentageOrAuto::Length(Au::from_f64_px(5.82)));
check("invalid", LengthOrPercentageOrAuto::Auto);
check("12 followed by invalid", LengthOrPercentageOrAuto::Length(Au::from_px(12)));
}
#[test]
pub fn split_html_space_chars_whitespace() {
assert!(split_html_space_chars("").collect::<Vec<_>>().is_empty());