2
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
4
5
- use std:: { io , str , task } ;
5
+ use std:: io ;
6
6
use std:: io:: { File , Command , Writer , TempDir } ;
7
+ use std:: task;
7
8
use serialize:: { json} ;
8
9
use serialize:: json:: ToJson ;
9
10
use test;
@@ -49,7 +50,9 @@ fn assert_json_eq(results: json::Json, expected: json::Json, message: String) {
49
50
let temp = TempDir :: new ( "rust-cssparser-tests" ) . unwrap ( ) ;
50
51
let results = results. to_pretty_str ( ) . append ( "\n " ) ;
51
52
let expected = expected. to_pretty_str ( ) . append ( "\n " ) ;
52
- task:: try ( proc ( ) {
53
+ // NB: The task try is to prevent error message generation from
54
+ // stopping us, we don't care about the result.
55
+ let _ = task:: try ( proc ( ) {
53
56
let mut result_path = temp. path ( ) . clone ( ) ;
54
57
result_path. push ( "results.json" ) ;
55
58
let mut expected_path = temp. path ( ) . clone ( ) ;
@@ -58,10 +61,10 @@ fn assert_json_eq(results: json::Json, expected: json::Json, message: String) {
58
61
write_whole_file ( & expected_path, expected. as_slice ( ) ) ;
59
62
Command :: new ( "colordiff" )
60
63
. arg ( "-u1000" )
61
- . arg ( result_path. display ( ) . to_str ( ) )
62
- . arg ( expected_path. display ( ) . to_str ( ) )
63
- . status ( ) . unwrap ( ) ;
64
- } ) . unwrap ( ) ;
64
+ . arg ( result_path. display ( ) . to_string ( ) )
65
+ . arg ( expected_path. display ( ) . to_string ( ) )
66
+ . status ( ) . unwrap ( )
67
+ } ) ;
65
68
66
69
fail ! ( message)
67
70
}
@@ -166,20 +169,20 @@ fn stylesheet_from_bytes() {
166
169
} ;
167
170
168
171
let result = {
169
- let css = get_string ( map, & "css_bytes" . to_string ( ) ) . unwrap ( ) . chars ( ) . map ( |c| {
172
+ let css = get_string ( & map, & "css_bytes" . to_string ( ) ) . unwrap ( ) . chars ( ) . map ( |c| {
170
173
assert ! ( c as u32 <= 0xFF ) ;
171
174
c as u8
172
175
} ) . collect :: < Vec < u8 > > ( ) ;
173
- let protocol_encoding_label = get_string ( map, & "protocol_encoding" . to_string ( ) ) ;
174
- let environment_encoding = get_string ( map, & "environment_encoding" . to_string ( ) )
176
+ let protocol_encoding_label = get_string ( & map, & "protocol_encoding" . to_string ( ) ) ;
177
+ let environment_encoding = get_string ( & map, & "environment_encoding" . to_string ( ) )
175
178
. and_then ( encoding_from_whatwg_label) ;
176
179
177
180
let ( mut rules, used_encoding) = parse_stylesheet_rules_from_bytes (
178
181
css. as_slice ( ) , protocol_encoding_label, environment_encoding) ;
179
182
180
183
( rules. collect :: < Vec < Result < Rule , SyntaxError > > > ( ) , used_encoding. name ( ) . to_string ( ) ) . to_json ( )
181
184
} ;
182
- assert_json_eq ( result, expected, json:: Object ( map) . to_str ( ) ) ;
185
+ assert_json_eq ( result, expected, json:: Object ( map) . to_string ( ) ) ;
183
186
} ) ;
184
187
185
188
fn get_string < ' a > ( map : & ' a json:: Object , key : & String ) -> Option < & ' a str > {
@@ -410,7 +413,7 @@ impl ToJson for ComponentValue {
410
413
String ( ref value) => JList ! ( JString !( "string" ) , value. to_json( ) ) ,
411
414
URL ( ref value) => JList ! ( JString !( "url" ) , value. to_json( ) ) ,
412
415
Delim ( '\\' ) => JString ! ( "\\ " ) ,
413
- Delim ( value) => json:: String ( str :: from_char ( value) ) ,
416
+ Delim ( value) => json:: String ( String :: from_char ( 1 , value) ) ,
414
417
415
418
Number ( ref value) => json:: List ( vec ! ( JString !( "number" ) ) + numeric ( value) ) ,
416
419
Percentage ( ref value) => json:: List ( vec ! ( JString !( "percentage" ) ) + numeric ( value) ) ,
0 commit comments