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());

View file

@ -4495,6 +4495,16 @@
],
"url": "/html/rendering/non-replaced-elements/the-hr-element-0/color.html"
},
{
"path": "html/rendering/non-replaced-elements/the-hr-element-0/width.html",
"references": [
[
"/html/rendering/non-replaced-elements/the-hr-element-0/width-ref.html",
"=="
]
],
"url": "/html/rendering/non-replaced-elements/the-hr-element-0/width.html"
},
{
"path": "html/rendering/non-replaced-elements/the-page/body_text_00ffff.xhtml",
"references": [

View file

@ -2313,9 +2313,6 @@
[HTMLHRElement interface: attribute size]
expected: FAIL
[HTMLHRElement interface: attribute width]
expected: FAIL
[HTMLHRElement interface: document.createElement("hr") must inherit property "align" with the proper type (0)]
expected: FAIL
@ -2325,9 +2322,6 @@
[HTMLHRElement interface: document.createElement("hr") must inherit property "size" with the proper type (3)]
expected: FAIL
[HTMLHRElement interface: document.createElement("hr") must inherit property "width" with the proper type (4)]
expected: FAIL
[HTMLPreElement interface: existence and properties of interface object]
expected: FAIL

View file

@ -1686,135 +1686,6 @@
[hr.size: IDL set to object "test-valueOf" followed by IDL get]
expected: FAIL
[hr.width: typeof IDL attribute]
expected: FAIL
[hr.width: IDL get with DOM attribute unset]
expected: FAIL
[hr.width: setAttribute() to "" followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo " followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to undefined followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to 7 followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to 1.5 followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to true followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to false followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to object "[object Object\]" followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to NaN followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to Infinity followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to -Infinity followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to "\\0" followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to null followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to object "test-toString" followed by IDL get]
expected: FAIL
[hr.width: setAttribute() to object "test-valueOf" followed by IDL get]
expected: FAIL
[hr.width: IDL set to "" followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo " followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to undefined followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to undefined followed by IDL get]
expected: FAIL
[hr.width: IDL set to 7 followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to 7 followed by IDL get]
expected: FAIL
[hr.width: IDL set to 1.5 followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to 1.5 followed by IDL get]
expected: FAIL
[hr.width: IDL set to true followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to true followed by IDL get]
expected: FAIL
[hr.width: IDL set to false followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to false followed by IDL get]
expected: FAIL
[hr.width: IDL set to object "[object Object\]" followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to object "[object Object\]" followed by IDL get]
expected: FAIL
[hr.width: IDL set to NaN followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to NaN followed by IDL get]
expected: FAIL
[hr.width: IDL set to Infinity followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to Infinity followed by IDL get]
expected: FAIL
[hr.width: IDL set to -Infinity followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to -Infinity followed by IDL get]
expected: FAIL
[hr.width: IDL set to "\\0" followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to null followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to null followed by IDL get]
expected: FAIL
[hr.width: IDL set to object "test-toString" followed by getAttribute()]
expected: FAIL
[hr.width: IDL set to object "test-toString" followed by IDL get]
expected: FAIL
[hr.width: IDL set to object "test-valueOf" followed by IDL get]
expected: FAIL
[hr.itemScope: typeof IDL attribute]
expected: FAIL

View file

@ -0,0 +1,19 @@
<style>
.hr {
color: gray;
border-style: inset;
border-width: 1px;
margin: 0.5em auto;
}
</style>
<div class=hr></div>
<div class=hr style="width: 50%"></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></div>

View file

@ -0,0 +1,15 @@
<!doctype html>
<meta charset="utf-8">
<title></title>
<link rel="match" href="width-ref.html">
<hr>
<hr width='50%'>
<hr width='100'>
<hr width='100foo'>
<hr width=' 100 '>
<hr width='100.99'>
<hr width='0'>
<hr width='00'>
<hr width='+0'>
<hr width='+00'>
<hr width='++0'>