33 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44
55use super :: * ;
6- use crate :: { ColorParser , PredefinedColorSpace , Color , RgbaLegacy } ;
6+ use crate :: { Color , ColorParser , PredefinedColorSpace , RgbaLegacy } ;
77use cssparser:: { Parser , ParserInput } ;
88use serde_json:: { self , json, Value } ;
99
1010fn almost_equals ( a : & Value , b : & Value ) -> bool {
1111 match ( a, b) {
12- ( & Value :: Number ( ref a) , & Value :: Number ( ref b) ) => {
12+ ( Value :: Number ( a) , Value :: Number ( b) ) => {
1313 let a = a. as_f64 ( ) . unwrap ( ) ;
1414 let b = b. as_f64 ( ) . unwrap ( ) ;
1515 ( a - b) . abs ( ) <= a. abs ( ) * 1e-6
1616 }
1717
1818 ( & Value :: Bool ( a) , & Value :: Bool ( b) ) => a == b,
19- ( & Value :: String ( ref a) , & Value :: String ( ref b) ) => a == b,
20- ( & Value :: Array ( ref a) , & Value :: Array ( ref b) ) => {
21- a. len ( ) == b. len ( )
22- && a. iter ( )
23- . zip ( b. iter ( ) )
24- . all ( |( ref a, ref b) | almost_equals ( * a, * b) )
19+ ( Value :: String ( a) , Value :: String ( b) ) => a == b,
20+ ( Value :: Array ( a) , Value :: Array ( b) ) => {
21+ a. len ( ) == b. len ( ) && a. iter ( ) . zip ( b. iter ( ) ) . all ( |( a, b) | almost_equals ( a, b) )
2522 }
2623 ( & Value :: Object ( _) , & Value :: Object ( _) ) => panic ! ( "Not implemented" ) ,
2724 ( & Value :: Null , & Value :: Null ) => true ,
@@ -43,8 +40,7 @@ fn assert_json_eq(results: Value, expected: Value, message: &str) {
4340 }
4441}
4542
46-
47- fn run_raw_json_tests < F : Fn ( Value , Value ) -> ( ) > ( json_data : & str , run : F ) {
43+ fn run_raw_json_tests < F : Fn ( Value , Value ) > ( json_data : & str , run : F ) {
4844 let items = match serde_json:: from_str ( json_data) {
4945 Ok ( Value :: Array ( items) ) => items,
5046 other => panic ! ( "Invalid JSON: {:?}" , other) ,
@@ -92,11 +88,14 @@ fn color3() {
9288#[ cfg_attr( all( miri, feature = "skip_long_tests" ) , ignore) ]
9389#[ test]
9490fn color3_hsl ( ) {
95- run_color_tests ( include_str ! ( "../src/css-parsing-tests/color3_hsl.json" ) , |c| {
96- c. ok ( )
97- . map ( |v| v. to_css_string ( ) . to_json ( ) )
98- . unwrap_or ( Value :: Null )
99- } )
91+ run_color_tests (
92+ include_str ! ( "../src/css-parsing-tests/color3_hsl.json" ) ,
93+ |c| {
94+ c. ok ( )
95+ . map ( |v| v. to_css_string ( ) . to_json ( ) )
96+ . unwrap_or ( Value :: Null )
97+ } ,
98+ )
10099}
101100
102101/// color3_keywords.json is different: R, G and B are in 0..255 rather than 0..1
@@ -115,11 +114,14 @@ fn color3_keywords() {
115114#[ cfg_attr( all( miri, feature = "skip_long_tests" ) , ignore) ]
116115#[ test]
117116fn color4_hwb ( ) {
118- run_color_tests ( include_str ! ( "../src/css-parsing-tests/color4_hwb.json" ) , |c| {
119- c. ok ( )
120- . map ( |v| v. to_css_string ( ) . to_json ( ) )
121- . unwrap_or ( Value :: Null )
122- } )
117+ run_color_tests (
118+ include_str ! ( "../src/css-parsing-tests/color4_hwb.json" ) ,
119+ |c| {
120+ c. ok ( )
121+ . map ( |v| v. to_css_string ( ) . to_json ( ) )
122+ . unwrap_or ( Value :: Null )
123+ } ,
124+ )
123125}
124126
125127#[ cfg_attr( all( miri, feature = "skip_long_tests" ) , ignore) ]
@@ -355,7 +357,7 @@ fn generic_parser() {
355357 ] ;
356358
357359 for ( input, expected) in TESTS {
358- let mut input = ParserInput :: new ( * input) ;
360+ let mut input = ParserInput :: new ( input) ;
359361 let mut input = Parser :: new ( & mut input) ;
360362
361363 let actual: OutputType = parse_color_with ( & TestColorParser , & mut input) . unwrap ( ) ;
0 commit comments