diff options
author | Manish Goregaokar <manishsmail@gmail.com> | 2016-08-02 15:43:52 +0530 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2016-08-02 19:22:03 +0530 |
commit | d1e45f78afaba96d55034e59befe32d6445e7148 (patch) | |
tree | 004e96c80b5e76d6c1c8277c76eb40dc12cf5bfa /tests/unit/style/parsing | |
parent | c6feae3c5ce2a25dfd809699eb0b8d2a96c1816e (diff) | |
download | servo-d1e45f78afaba96d55034e59befe32d6445e7148.tar.gz servo-d1e45f78afaba96d55034e59befe32d6445e7148.zip |
Add serialize_four_sides, use for serializing BorderRadius
Diffstat (limited to 'tests/unit/style/parsing')
-rw-r--r-- | tests/unit/style/parsing/basic_shape.rs | 50 | ||||
-rw-r--r-- | tests/unit/style/parsing/mod.rs | 14 | ||||
-rw-r--r-- | tests/unit/style/parsing/position.rs | 4 |
3 files changed, 58 insertions, 10 deletions
diff --git a/tests/unit/style/parsing/basic_shape.rs b/tests/unit/style/parsing/basic_shape.rs index 0f8f6f4ccb5..dbe1c209baf 100644 --- a/tests/unit/style/parsing/basic_shape.rs +++ b/tests/unit/style/parsing/basic_shape.rs @@ -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,11 +40,9 @@ 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 \ @@ -35,6 +50,31 @@ fn test_inset() { } #[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%)"); assert_roundtrip_basicshape!(Circle::parse, "circle()", "circle(at 50% 50%)"); diff --git a/tests/unit/style/parsing/mod.rs b/tests/unit/style/parsing/mod.rs index 76ff804b97a..0fbe6c8bacf 100644 --- a/tests/unit/style/parsing/mod.rs +++ b/tests/unit/style/parsing/mod.rs @@ -4,26 +4,30 @@ //! Tests for parsing and serialization of values/properties -use cssparser::Parser; +use cssparser::{Parser, ToCss}; fn parse<T, F: Fn(&mut Parser) -> Result<T, ()>>(f: F, s: &str) -> Result<T, ()> { let mut parser = Parser::new(s); f(&mut parser) } +fn to_string<T: ToCss>(x: T) -> String { + let mut serialized = String::new(); + x.to_css(&mut serialized).expect("Failed to serialize"); + serialized +} + // This is a macro so that the file/line information // is preserved in the panic macro_rules! assert_roundtrip { ($fun:expr, $input:expr, $output:expr) => { let parsed = $crate::parsing::parse($fun, $input) .expect(&format!("Failed to parse {}", $input)); - let mut serialized = String::new(); - ::cssparser::ToCss::to_css(&parsed, &mut serialized) - .expect("Failed to serialize"); + let serialized = $crate::parsing::to_string(parsed); assert_eq!(serialized, $output); } } mod basic_shape; -mod position;
\ No newline at end of file +mod position; diff --git a/tests/unit/style/parsing/position.rs b/tests/unit/style/parsing/position.rs index bc4f1c51433..ca55b2c452d 100644 --- a/tests/unit/style/parsing/position.rs +++ b/tests/unit/style/parsing/position.rs @@ -25,6 +25,10 @@ fn test_position() { assert_roundtrip!(Position::parse, "center 10%", "50% 10%"); assert_roundtrip!(Position::parse, "right 10%", "100% 10%"); + // Only keywords can be reordered + assert!(parse(Position::parse, "top 40%").is_err()); + assert!(parse(Position::parse, "40% left").is_err()); + // we don't yet handle 4-valued positions // https://github.com/servo/servo/issues/12690 } |