mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Make util::str::parse_length work with floats
This commit is contained in:
parent
02a8e8dd16
commit
30ea772939
4 changed files with 4 additions and 1 deletions
|
@ -367,7 +367,7 @@ pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto {
|
|||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ pub fn test_parse_length() {
|
|||
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)));
|
||||
}
|
||||
|
|
|
@ -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: 100.99px"></div>
|
||||
<div class=hr style="width: 0%"></div>
|
||||
<div class=hr style="width: 0%"></div>
|
||||
<div class=hr style="width: 0%"></div>
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
<hr width='100'>
|
||||
<hr width='100foo'>
|
||||
<hr width=' 100 '>
|
||||
<hr width='100.99'>
|
||||
<hr width='0'>
|
||||
<hr width='00'>
|
||||
<hr width='+0'>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue