Make util::str::parse_length work with floats

This commit is contained in:
Corey Farwell 2015-11-14 12:36:18 -05:00
parent 02a8e8dd16
commit 30ea772939
4 changed files with 4 additions and 1 deletions

View file

@ -367,7 +367,7 @@ pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto {
} }
match FromStr::from_str(value) { match FromStr::from_str(value) {
Ok(number) => LengthOrPercentageOrAuto::Length(Au::from_px(number)), Ok(number) => LengthOrPercentageOrAuto::Length(Au::from_f64_px(number)),
Err(_) => LengthOrPercentageOrAuto::Auto, Err(_) => LengthOrPercentageOrAuto::Auto,
} }
} }

View file

@ -17,6 +17,7 @@ pub fn test_parse_length() {
check("0", LengthOrPercentageOrAuto::Length(Au::from_px(0))); check("0", LengthOrPercentageOrAuto::Length(Au::from_px(0)));
check("0.000%", LengthOrPercentageOrAuto::Percentage(0.0)); check("0.000%", LengthOrPercentageOrAuto::Percentage(0.0));
check("+5.82%", LengthOrPercentageOrAuto::Percentage(0.0582)); check("+5.82%", LengthOrPercentageOrAuto::Percentage(0.0582));
check("5.82", LengthOrPercentageOrAuto::Length(Au::from_f64_px(5.82)));
check("invalid", LengthOrPercentageOrAuto::Auto); check("invalid", LengthOrPercentageOrAuto::Auto);
check("12 followed by invalid", LengthOrPercentageOrAuto::Length(Au::from_px(12))); check("12 followed by invalid", LengthOrPercentageOrAuto::Length(Au::from_px(12)));
} }

View file

@ -11,6 +11,7 @@
<div class=hr style="width: 100px"></div> <div class=hr style="width: 100px"></div>
<div class=hr style="width: 100px"></div> <div class=hr style="width: 100px"></div>
<div class=hr style="width: 100px"></div> <div class=hr style="width: 100px"></div>
<div class=hr style="width: 100.99px"></div>
<div class=hr style="width: 0%"></div> <div class=hr style="width: 0%"></div>
<div class=hr style="width: 0%"></div> <div class=hr style="width: 0%"></div>
<div class=hr style="width: 0%"></div> <div class=hr style="width: 0%"></div>

View file

@ -7,6 +7,7 @@
<hr width='100'> <hr width='100'>
<hr width='100foo'> <hr width='100foo'>
<hr width=' 100 '> <hr width=' 100 '>
<hr width='100.99'>
<hr width='0'> <hr width='0'>
<hr width='00'> <hr width='00'>
<hr width='+0'> <hr width='+0'>