3
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
4
5
5
use 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 } ;
9
8
10
9
fn almost_equals ( a : & Value , b : & Value ) -> bool {
11
10
match ( a, b) {
12
- ( & Value :: Number ( ref a) , & Value :: Number ( ref b) ) => {
11
+ ( Value :: Number ( a) , Value :: Number ( b) ) => {
13
12
let a = a. as_f64 ( ) . unwrap ( ) ;
14
13
let b = b. as_f64 ( ) . unwrap ( ) ;
15
14
( a - b) . abs ( ) <= a. abs ( ) * 1e-6
16
15
}
17
16
18
17
( & 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) )
25
21
}
26
22
( & Value :: Object ( _) , & Value :: Object ( _) ) => panic ! ( "Not implemented" ) ,
27
23
( & Value :: Null , & Value :: Null ) => true ,
@@ -43,8 +39,7 @@ fn assert_json_eq(results: Value, expected: Value, message: &str) {
43
39
}
44
40
}
45
41
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 ) {
48
43
let items = match serde_json:: from_str ( json_data) {
49
44
Ok ( Value :: Array ( items) ) => items,
50
45
other => panic ! ( "Invalid JSON: {:?}" , other) ,
@@ -92,11 +87,14 @@ fn color3() {
92
87
#[ cfg_attr( all( miri, feature = "skip_long_tests" ) , ignore) ]
93
88
#[ test]
94
89
fn 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
+ )
100
98
}
101
99
102
100
/// color3_keywords.json is different: R, G and B are in 0..255 rather than 0..1
@@ -115,11 +113,14 @@ fn color3_keywords() {
115
113
#[ cfg_attr( all( miri, feature = "skip_long_tests" ) , ignore) ]
116
114
#[ test]
117
115
fn 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
+ )
123
124
}
124
125
125
126
#[ cfg_attr( all( miri, feature = "skip_long_tests" ) , ignore) ]
@@ -355,7 +356,7 @@ fn generic_parser() {
355
356
] ;
356
357
357
358
for ( input, expected) in TESTS {
358
- let mut input = ParserInput :: new ( * input) ;
359
+ let mut input = ParserInput :: new ( input) ;
359
360
let mut input = Parser :: new ( & mut input) ;
360
361
361
362
let actual: OutputType = parse_color_with ( & TestColorParser , & mut input) . unwrap ( ) ;
0 commit comments