33 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44
55use super :: * ;
6- use crate :: { ColorParser , PredefinedColorSpace , Color , RgbaLegacy } ;
7- use cssparser:: { Parser , ParserInput } ;
8- use serde_json:: { self , json, Value } ;
6+ use cssparser:: ParserInput ;
7+ use serde_json:: { json, Value } ;
98
109fn almost_equals ( a : & Value , b : & Value ) -> bool {
1110 match ( a, b) {
12- ( & Value :: Number ( ref a) , & Value :: Number ( ref b) ) => {
11+ ( Value :: Number ( a) , Value :: Number ( b) ) => {
1312 let a = a. as_f64 ( ) . unwrap ( ) ;
1413 let b = b. as_f64 ( ) . unwrap ( ) ;
1514 ( a - b) . abs ( ) <= a. abs ( ) * 1e-6
1615 }
1716
1817 ( & 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) )
18+ ( Value :: String ( a) , Value :: String ( b) ) => a == b,
19+ ( Value :: Array ( a) , Value :: Array ( b) ) => {
20+ a. len ( ) == b. len ( ) && a. iter ( ) . zip ( b. iter ( ) ) . all ( |( a, b) | almost_equals ( a, b) )
2521 }
2622 ( & Value :: Object ( _) , & Value :: Object ( _) ) => panic ! ( "Not implemented" ) ,
2723 ( & Value :: Null , & Value :: Null ) => true ,
@@ -43,8 +39,7 @@ fn assert_json_eq(results: Value, expected: Value, message: &str) {
4339 }
4440}
4541
46-
47- fn run_raw_json_tests < F : Fn ( Value , Value ) -> ( ) > ( json_data : & str , run : F ) {
42+ fn run_raw_json_tests < F : Fn ( Value , Value ) > ( json_data : & str , run : F ) {
4843 let items = match serde_json:: from_str ( json_data) {
4944 Ok ( Value :: Array ( items) ) => items,
5045 other => panic ! ( "Invalid JSON: {:?}" , other) ,
@@ -92,11 +87,14 @@ fn color3() {
9287#[ cfg_attr( all( miri, feature = "skip_long_tests" ) , ignore) ]
9388#[ test]
9489fn 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- } )
90+ run_color_tests (
91+ include_str ! ( "../src/css-parsing-tests/color3_hsl.json" ) ,
92+ |c| {
93+ c. ok ( )
94+ . map ( |v| v. to_css_string ( ) . to_json ( ) )
95+ . unwrap_or ( Value :: Null )
96+ } ,
97+ )
10098}
10199
102100/// color3_keywords.json is different: R, G and B are in 0..255 rather than 0..1
@@ -115,11 +113,14 @@ fn color3_keywords() {
115113#[ cfg_attr( all( miri, feature = "skip_long_tests" ) , ignore) ]
116114#[ test]
117115fn 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- } )
116+ run_color_tests (
117+ include_str ! ( "../src/css-parsing-tests/color4_hwb.json" ) ,
118+ |c| {
119+ c. ok ( )
120+ . map ( |v| v. to_css_string ( ) . to_json ( ) )
121+ . unwrap_or ( Value :: Null )
122+ } ,
123+ )
123124}
124125
125126#[ cfg_attr( all( miri, feature = "skip_long_tests" ) , ignore) ]
@@ -355,7 +356,7 @@ fn generic_parser() {
355356 ] ;
356357
357358 for ( input, expected) in TESTS {
358- let mut input = ParserInput :: new ( * input) ;
359+ let mut input = ParserInput :: new ( input) ;
359360 let mut input = Parser :: new ( & mut input) ;
360361
361362 let actual: OutputType = parse_color_with ( & TestColorParser , & mut input) . unwrap ( ) ;
0 commit comments