Fix border shorthand serialization

Fix border shorthand serialization when sides are not identical
This commit is contained in:
Karl 2017-02-06 21:35:45 -05:00
parent 74e7afa1c8
commit ec865c3702
2 changed files with 97 additions and 7 deletions

View file

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