mirror of
https://github.com/servo/servo.git
synced 2025-08-11 16:35:33 +01:00
script: Fix panic in htmlimageelement.rs
using str::find()
to find character boundaries. (#32980)
* fix loop with chars().enumerate() by using find() Signed-off-by: Kopanov Anton <anton.kopanov@ya.ru> * Add documentation to parser and fix some small issues - Rename the properties of `Descriptor` so that they are full words - Use the Rust-parser to parse doubles - Add documentation and restructure parser to be more readable Signed-off-by: Martin Robinson <mrobinson@igalia.com> --------- Signed-off-by: Kopanov Anton <anton.kopanov@ya.ru> Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
e85491b5fc
commit
ad45fa0a19
7 changed files with 285 additions and 195 deletions
|
@ -13,30 +13,30 @@ fn no_value() {
|
|||
#[test]
|
||||
fn width_one_value() {
|
||||
let first_descriptor = Descriptor {
|
||||
wid: Some(320),
|
||||
den: None,
|
||||
width: Some(320),
|
||||
density: None,
|
||||
};
|
||||
let first_imagesource = ImageSource {
|
||||
url: "small-image.jpg".to_string(),
|
||||
descriptor: first_descriptor,
|
||||
};
|
||||
let sources = &[first_imagesource];
|
||||
assert_eq!(parse_a_srcset_attribute("small-image.jpg, 320w"), sources);
|
||||
assert_eq!(parse_a_srcset_attribute("small-image.jpg 320w"), sources);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn width_two_value() {
|
||||
let first_descriptor = Descriptor {
|
||||
wid: Some(320),
|
||||
den: None,
|
||||
width: Some(320),
|
||||
density: None,
|
||||
};
|
||||
let first_imagesource = ImageSource {
|
||||
url: "small-image.jpg".to_string(),
|
||||
descriptor: first_descriptor,
|
||||
};
|
||||
let second_descriptor = Descriptor {
|
||||
wid: Some(480),
|
||||
den: None,
|
||||
width: Some(480),
|
||||
density: None,
|
||||
};
|
||||
let second_imagesource = ImageSource {
|
||||
url: "medium-image.jpg".to_string(),
|
||||
|
@ -52,24 +52,24 @@ fn width_two_value() {
|
|||
#[test]
|
||||
fn width_three_value() {
|
||||
let first_descriptor = Descriptor {
|
||||
wid: Some(320),
|
||||
den: None,
|
||||
width: Some(320),
|
||||
density: None,
|
||||
};
|
||||
let first_imagesource = ImageSource {
|
||||
url: "smallImage.jpg".to_string(),
|
||||
descriptor: first_descriptor,
|
||||
};
|
||||
let second_descriptor = Descriptor {
|
||||
wid: Some(480),
|
||||
den: None,
|
||||
width: Some(480),
|
||||
density: None,
|
||||
};
|
||||
let second_imagesource = ImageSource {
|
||||
url: "mediumImage.jpg".to_string(),
|
||||
descriptor: second_descriptor,
|
||||
};
|
||||
let third_descriptor = Descriptor {
|
||||
wid: Some(800),
|
||||
den: None,
|
||||
width: Some(800),
|
||||
density: None,
|
||||
};
|
||||
let third_imagesource = ImageSource {
|
||||
url: "largeImage.jpg".to_string(),
|
||||
|
@ -89,8 +89,8 @@ fn width_three_value() {
|
|||
#[test]
|
||||
fn density_value() {
|
||||
let first_descriptor = Descriptor {
|
||||
wid: None,
|
||||
den: Some(1.0),
|
||||
width: None,
|
||||
density: Some(1.0),
|
||||
};
|
||||
let first_imagesource = ImageSource {
|
||||
url: "small-image.jpg".to_string(),
|
||||
|
@ -103,8 +103,8 @@ fn density_value() {
|
|||
#[test]
|
||||
fn without_descriptor() {
|
||||
let first_descriptor = Descriptor {
|
||||
wid: None,
|
||||
den: None,
|
||||
width: None,
|
||||
density: None,
|
||||
};
|
||||
let first_imagesource = ImageSource {
|
||||
url: "small-image.jpg".to_string(),
|
||||
|
@ -127,8 +127,8 @@ fn two_descriptor() {
|
|||
#[test]
|
||||
fn decimal_descriptor() {
|
||||
let first_descriptor = Descriptor {
|
||||
wid: None,
|
||||
den: Some(2.2),
|
||||
width: None,
|
||||
density: Some(2.2),
|
||||
};
|
||||
let first_imagesource = ImageSource {
|
||||
url: "small-image.jpg".to_string(),
|
||||
|
@ -141,16 +141,16 @@ fn decimal_descriptor() {
|
|||
#[test]
|
||||
fn different_descriptor() {
|
||||
let first_descriptor = Descriptor {
|
||||
wid: Some(320),
|
||||
den: None,
|
||||
width: Some(320),
|
||||
density: None,
|
||||
};
|
||||
let first_imagesource = ImageSource {
|
||||
url: "small-image.jpg".to_string(),
|
||||
descriptor: first_descriptor,
|
||||
};
|
||||
let second_descriptor = Descriptor {
|
||||
wid: None,
|
||||
den: Some(2.2),
|
||||
width: None,
|
||||
density: Some(2.2),
|
||||
};
|
||||
let second_imagesource = ImageSource {
|
||||
url: "medium-image.jpg".to_string(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue