fix impl of parse_length()

This commit is contained in:
rohan.prinja 2015-11-09 16:09:43 +09:00 committed by Corey Farwell
parent 50be4bb09e
commit 337066063a
5 changed files with 47 additions and 9 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,25 @@
* 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("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());