Move util::str::parse_length into 'style' component.

The function is only used in the 'style' component, so we'll move it
there alongside other relevant parse functions.
This commit is contained in:
Corey Farwell 2016-03-24 10:37:14 -04:00
parent a8264ecc1f
commit 5efbf0fa8f
4 changed files with 91 additions and 92 deletions

View file

@ -2,8 +2,9 @@
* 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 style::attr::AttrValue;
use util::str::DOMString;
use app_units::Au;
use style::attr::{AttrValue, parse_length};
use util::str::{DOMString, LengthOrPercentageOrAuto};
#[test]
fn test_from_limited_i32_should_be_default_when_less_than_0() {
@ -31,3 +32,18 @@ fn test_from_limited_i32_should_keep_parsed_value_when_not_an_int() {
_ => panic!("expected an successful parsing")
}
}
#[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)));
}

View file

@ -2,25 +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 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)));
}
use util::str::{search_index, split_html_space_chars, str_join};
#[test]
pub fn split_html_space_chars_whitespace() {