mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Add serialize_four_sides, use for serializing BorderRadius
This commit is contained in:
parent
c6feae3c5c
commit
d1e45f78af
5 changed files with 110 additions and 27 deletions
|
@ -2,7 +2,7 @@
|
|||
* 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 parsing::parse;
|
||||
use parsing::{parse, to_string};
|
||||
use style::values::specified::basic_shape::*;
|
||||
|
||||
// Ensure that basic-shape sub-functions parse as both basic shapes
|
||||
|
@ -14,6 +14,23 @@ macro_rules! assert_roundtrip_basicshape {
|
|||
}
|
||||
}
|
||||
|
||||
macro_rules! assert_border_radius_values {
|
||||
($input:expr; $tlw:expr, $trw:expr, $blw:expr, $brw:expr ;
|
||||
$tlh:expr, $trh:expr, $blh:expr, $brh:expr) => {
|
||||
let input = parse(BorderRadius::parse, $input)
|
||||
.expect(&format!("Failed parsing {} as border radius",
|
||||
$input));
|
||||
assert_eq!(to_string(input.top_left.0.width), $tlw);
|
||||
assert_eq!(to_string(input.top_right.0.width), $trw);
|
||||
assert_eq!(to_string(input.bottom_left.0.width), $blw);
|
||||
assert_eq!(to_string(input.bottom_right.0.width), $brw);
|
||||
assert_eq!(to_string(input.top_left.0.height), $tlh);
|
||||
assert_eq!(to_string(input.top_right.0.height), $trh);
|
||||
assert_eq!(to_string(input.bottom_left.0.height), $blh);
|
||||
assert_eq!(to_string(input.bottom_right.0.height), $brh);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_inset() {
|
||||
// these are actually wrong, we should be serializing to the minimum possible result
|
||||
|
@ -23,17 +40,40 @@ fn test_inset() {
|
|||
assert_roundtrip_basicshape!(InsetRect::parse, "inset(10px 20%)", "inset(10px 20% 10px 20%)");
|
||||
|
||||
assert_roundtrip_basicshape!(InsetRect::parse, "inset(10px round 10px)",
|
||||
"inset(10px 10px 10px 10px round 10px 10px 10px 10px \
|
||||
/ 10px 10px 10px 10px)");
|
||||
"inset(10px 10px 10px 10px round 10px)");
|
||||
assert_roundtrip_basicshape!(InsetRect::parse, "inset(10px round 10px 20px 30px 40px)",
|
||||
"inset(10px 10px 10px 10px round 10px 20px 30px 40px \
|
||||
/ 10px 20px 30px 40px)");
|
||||
"inset(10px 10px 10px 10px round 10px 20px 30px 40px)");
|
||||
assert_roundtrip_basicshape!(InsetRect::parse, "inset(10px 10px 10px 10px round 10px 20px 30px 40px \
|
||||
/ 1px 2px 3px 4px)",
|
||||
"inset(10px 10px 10px 10px round 10px 20px 30px 40px \
|
||||
/ 1px 2px 3px 4px)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_border_radius() {
|
||||
assert_border_radius_values!("10px";
|
||||
"10px", "10px", "10px", "10px" ;
|
||||
"10px", "10px", "10px", "10px");
|
||||
assert_border_radius_values!("10px 20px";
|
||||
"10px", "20px", "10px", "20px" ;
|
||||
"10px", "20px", "10px", "20px");
|
||||
assert_border_radius_values!("10px 20px 30px";
|
||||
"10px", "20px", "30px", "20px" ;
|
||||
"10px", "20px", "30px", "20px");
|
||||
assert_border_radius_values!("10px 20px 30px 40px";
|
||||
"10px", "20px", "30px", "40px" ;
|
||||
"10px", "20px", "30px", "40px");
|
||||
assert_border_radius_values!("10% / 20px";
|
||||
"10%", "10%", "10%", "10%" ;
|
||||
"20px", "20px", "20px", "20px");
|
||||
assert_border_radius_values!("10px / 20px 30px";
|
||||
"10px", "10px", "10px", "10px" ;
|
||||
"20px", "30px", "20px", "30px");
|
||||
assert_border_radius_values!("10px 20px 30px 40px / 1px 2px 3px 4px";
|
||||
"10px", "20px", "30px", "40px" ;
|
||||
"1px", "2px", "3px", "4px");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_circle() {
|
||||
assert_roundtrip_basicshape!(Circle::parse, "circle(at center)", "circle(at 50% 50%)");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue