mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #15416 - karlding:servo-15395_border_serialization, r=emilio
Fix border shorthand serialization Fix border shorthand serialization when sides are not identical. I think I managed to get the serialization to work as expected. I added a check to ensure that the **border-width**, **border-style** and **border-color** were the same, before performing the serialization. I'm still a Rust newbie, so if there's a more idiomatic way of doing things (or any critiques in general), please let me know! --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #15395 <!-- Either: --> - [X] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15416) <!-- Reviewable:end -->
This commit is contained in:
commit
f0257364c2
2 changed files with 97 additions and 7 deletions
|
@ -186,6 +186,72 @@ mod shorthand_serialization {
|
|||
assert_eq!(serialization, "margin: 8px 12px 10px 14px;");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn different_longhands_should_serialize_to_long_form() {
|
||||
let mut properties = Vec::new();
|
||||
|
||||
let solid = DeclaredValue::Value(BorderStyle::solid);
|
||||
|
||||
properties.push(PropertyDeclaration::BorderTopStyle(solid.clone()));
|
||||
properties.push(PropertyDeclaration::BorderRightStyle(solid.clone()));
|
||||
properties.push(PropertyDeclaration::BorderBottomStyle(solid.clone()));
|
||||
properties.push(PropertyDeclaration::BorderLeftStyle(solid.clone()));
|
||||
|
||||
let px_30 = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(30f32)));
|
||||
let px_10 = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(10f32)));
|
||||
|
||||
properties.push(PropertyDeclaration::BorderTopWidth(px_30.clone()));
|
||||
properties.push(PropertyDeclaration::BorderRightWidth(px_30.clone()));
|
||||
properties.push(PropertyDeclaration::BorderBottomWidth(px_30.clone()));
|
||||
properties.push(PropertyDeclaration::BorderLeftWidth(px_10.clone()));
|
||||
|
||||
let blue = DeclaredValue::Value(CSSColor {
|
||||
parsed: ComputedColor::RGBA(RGBA::new(0, 0, 255, 255)),
|
||||
authored: None
|
||||
});
|
||||
|
||||
properties.push(PropertyDeclaration::BorderTopColor(blue.clone()));
|
||||
properties.push(PropertyDeclaration::BorderRightColor(blue.clone()));
|
||||
properties.push(PropertyDeclaration::BorderBottomColor(blue.clone()));
|
||||
properties.push(PropertyDeclaration::BorderLeftColor(blue.clone()));
|
||||
|
||||
let serialization = shorthand_properties_to_string(properties);
|
||||
assert_eq!(serialization,
|
||||
"border-style: solid; border-width: 30px 30px 30px 10px; border-color: rgb(0, 0, 255);");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn same_longhands_should_serialize_correctly() {
|
||||
let mut properties = Vec::new();
|
||||
|
||||
let solid = DeclaredValue::Value(BorderStyle::solid);
|
||||
|
||||
properties.push(PropertyDeclaration::BorderTopStyle(solid.clone()));
|
||||
properties.push(PropertyDeclaration::BorderRightStyle(solid.clone()));
|
||||
properties.push(PropertyDeclaration::BorderBottomStyle(solid.clone()));
|
||||
properties.push(PropertyDeclaration::BorderLeftStyle(solid.clone()));
|
||||
|
||||
let px_30 = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(30f32)));
|
||||
|
||||
properties.push(PropertyDeclaration::BorderTopWidth(px_30.clone()));
|
||||
properties.push(PropertyDeclaration::BorderRightWidth(px_30.clone()));
|
||||
properties.push(PropertyDeclaration::BorderBottomWidth(px_30.clone()));
|
||||
properties.push(PropertyDeclaration::BorderLeftWidth(px_30.clone()));
|
||||
|
||||
let blue = DeclaredValue::Value(CSSColor {
|
||||
parsed: ComputedColor::RGBA(RGBA::new(0, 0, 255, 255)),
|
||||
authored: None
|
||||
});
|
||||
|
||||
properties.push(PropertyDeclaration::BorderTopColor(blue.clone()));
|
||||
properties.push(PropertyDeclaration::BorderRightColor(blue.clone()));
|
||||
properties.push(PropertyDeclaration::BorderBottomColor(blue.clone()));
|
||||
properties.push(PropertyDeclaration::BorderLeftColor(blue.clone()));
|
||||
|
||||
let serialization = shorthand_properties_to_string(properties);
|
||||
assert_eq!(serialization, "border: 30px solid rgb(0, 0, 255);");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn padding_should_serialize_correctly() {
|
||||
let mut properties = Vec::new();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue