@@ -58,10 +58,10 @@ fn assert_json_eq(results: json::Json, expected: json::Json, message: String) {
58
58
write_whole_file ( & expected_path, expected. as_slice ( ) ) ;
59
59
Command :: new ( "colordiff" )
60
60
. arg ( "-u1000" )
61
- . arg ( result_path. display ( ) . to_str ( ) )
62
- . arg ( expected_path. display ( ) . to_str ( ) )
63
- . status ( ) . unwrap ( ) ;
64
- } ) . unwrap ( ) ;
61
+ . arg ( result_path)
62
+ . arg ( expected_path)
63
+ . status ( ) . unwrap_or_else ( |e| fail ! ( "Failed to get status of colordiff: {}" , e ) ) ;
64
+ } ) . unwrap_or_else ( |_e| fail ! ( "Failed to execute task" ) ) ;
65
65
66
66
fail ! ( message)
67
67
}
@@ -102,84 +102,84 @@ fn run_json_tests<T: ToJson>(json_data: &str, parse: |input: &str| -> T) {
102
102
103
103
#[ test]
104
104
fn component_value_list ( ) {
105
- run_json_tests ( include_str ! ( "css-parsing-tests/component_value_list.json" ) , |input| {
105
+ run_json_tests ( include_str ! ( "../ css-parsing-tests/component_value_list.json" ) , |input| {
106
106
tokenize ( input) . map ( |( c, _) | c) . collect :: < Vec < ComponentValue > > ( )
107
107
} ) ;
108
108
}
109
109
110
110
111
111
#[ test]
112
112
fn one_component_value ( ) {
113
- run_json_tests ( include_str ! ( "css-parsing-tests/one_component_value.json" ) , |input| {
113
+ run_json_tests ( include_str ! ( "../ css-parsing-tests/one_component_value.json" ) , |input| {
114
114
parse_one_component_value ( tokenize ( input) )
115
115
} ) ;
116
116
}
117
117
118
118
119
119
#[ test]
120
120
fn declaration_list ( ) {
121
- run_json_tests ( include_str ! ( "css-parsing-tests/declaration_list.json" ) , |input| {
121
+ run_json_tests ( include_str ! ( "../ css-parsing-tests/declaration_list.json" ) , |input| {
122
122
parse_declaration_list ( tokenize ( input) ) . collect :: < Vec < Result < DeclarationListItem , SyntaxError > > > ( )
123
123
} ) ;
124
124
}
125
125
126
126
127
127
#[ test]
128
128
fn one_declaration ( ) {
129
- run_json_tests ( include_str ! ( "css-parsing-tests/one_declaration.json" ) , |input| {
129
+ run_json_tests ( include_str ! ( "../ css-parsing-tests/one_declaration.json" ) , |input| {
130
130
parse_one_declaration ( tokenize ( input) )
131
131
} ) ;
132
132
}
133
133
134
134
135
135
#[ test]
136
136
fn rule_list ( ) {
137
- run_json_tests ( include_str ! ( "css-parsing-tests/rule_list.json" ) , |input| {
137
+ run_json_tests ( include_str ! ( "../ css-parsing-tests/rule_list.json" ) , |input| {
138
138
parse_rule_list ( tokenize ( input) ) . collect :: < Vec < Result < Rule , SyntaxError > > > ( )
139
139
} ) ;
140
140
}
141
141
142
142
143
143
#[ test]
144
144
fn stylesheet ( ) {
145
- run_json_tests ( include_str ! ( "css-parsing-tests/stylesheet.json" ) , |input| {
145
+ run_json_tests ( include_str ! ( "../ css-parsing-tests/stylesheet.json" ) , |input| {
146
146
parse_stylesheet_rules ( tokenize ( input) ) . collect :: < Vec < Result < Rule , SyntaxError > > > ( )
147
147
} ) ;
148
148
}
149
149
150
150
151
151
#[ test]
152
152
fn one_rule ( ) {
153
- run_json_tests ( include_str ! ( "css-parsing-tests/one_rule.json" ) , |input| {
153
+ run_json_tests ( include_str ! ( "../ css-parsing-tests/one_rule.json" ) , |input| {
154
154
parse_one_rule ( tokenize ( input) )
155
155
} ) ;
156
156
}
157
157
158
158
159
159
#[ test]
160
160
fn stylesheet_from_bytes ( ) {
161
- run_raw_json_tests ( include_str ! ( "css-parsing-tests/stylesheet_bytes.json" ) ,
161
+ run_raw_json_tests ( include_str ! ( "../ css-parsing-tests/stylesheet_bytes.json" ) ,
162
162
|input, expected| {
163
163
let map = match input {
164
164
json:: Object ( map) => map,
165
165
_ => fail ! ( "Unexpected JSON" )
166
166
} ;
167
167
168
168
let result = {
169
- let css = get_string ( map, & "css_bytes" . to_string ( ) ) . unwrap ( ) . chars ( ) . map ( |c| {
169
+ let css = get_string ( & map, & "css_bytes" . to_string ( ) ) . unwrap ( ) . chars ( ) . map ( |c| {
170
170
assert ! ( c as u32 <= 0xFF ) ;
171
171
c as u8
172
172
} ) . 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 ( ) )
173
+ let protocol_encoding_label = get_string ( & map, & "protocol_encoding" . to_string ( ) ) ;
174
+ let environment_encoding = get_string ( & map, & "environment_encoding" . to_string ( ) )
175
175
. and_then ( encoding_from_whatwg_label) ;
176
176
177
177
let ( mut rules, used_encoding) = parse_stylesheet_rules_from_bytes (
178
178
css. as_slice ( ) , protocol_encoding_label, environment_encoding) ;
179
179
180
180
( rules. collect :: < Vec < Result < Rule , SyntaxError > > > ( ) , used_encoding. name ( ) . to_string ( ) ) . to_json ( )
181
181
} ;
182
- assert_json_eq ( result, expected, json:: Object ( map) . to_str ( ) ) ;
182
+ assert_json_eq ( result, expected, json:: Object ( map) . to_pretty_str ( ) ) ;
183
183
} ) ;
184
184
185
185
fn get_string < ' a > ( map : & ' a json:: Object , key : & String ) -> Option < & ' a str > {
@@ -205,20 +205,20 @@ fn run_color_tests(json_data: &str, to_json: |result: Option<Color>| -> json::Js
205
205
206
206
#[ test]
207
207
fn color3 ( ) {
208
- run_color_tests ( include_str ! ( "css-parsing-tests/color3.json" ) , |c| c. to_json ( ) )
208
+ run_color_tests ( include_str ! ( "../ css-parsing-tests/color3.json" ) , |c| c. to_json ( ) )
209
209
}
210
210
211
211
212
212
#[ test]
213
213
fn color3_hsl ( ) {
214
- run_color_tests ( include_str ! ( "css-parsing-tests/color3_hsl.json" ) , |c| c. to_json ( ) )
214
+ run_color_tests ( include_str ! ( "../ css-parsing-tests/color3_hsl.json" ) , |c| c. to_json ( ) )
215
215
}
216
216
217
217
218
218
/// color3_keywords.json is different: R, G and B are in 0..255 rather than 0..1
219
219
#[ test]
220
220
fn color3_keywords ( ) {
221
- run_color_tests ( include_str ! ( "css-parsing-tests/color3_keywords.json" ) , |c| {
221
+ run_color_tests ( include_str ! ( "../ css-parsing-tests/color3_keywords.json" ) , |c| {
222
222
match c {
223
223
Some ( RGBA ( RGBA { red : r, green : g, blue : b, alpha : a } ) )
224
224
=> vec ! ( r * 255. , g * 255. , b * 255. , a) . to_json ( ) ,
@@ -252,15 +252,15 @@ fn bench_color_lookup_fail(b: &mut test::Bencher) {
252
252
253
253
#[ test]
254
254
fn nth ( ) {
255
- run_json_tests ( include_str ! ( "css-parsing-tests/An+B.json" ) , |input| {
255
+ run_json_tests ( include_str ! ( "../ css-parsing-tests/An+B.json" ) , |input| {
256
256
parse_nth ( tokenize ( input) . map ( |( c, _) | c) . collect :: < Vec < ComponentValue > > ( ) . as_slice ( ) )
257
257
} ) ;
258
258
}
259
259
260
260
261
261
#[ test]
262
262
fn serializer ( ) {
263
- run_json_tests ( include_str ! ( "css-parsing-tests/component_value_list.json" ) , |input| {
263
+ run_json_tests ( include_str ! ( "../ css-parsing-tests/component_value_list.json" ) , |input| {
264
264
let component_values = tokenize ( input) . map ( |( c, _) | c) . collect :: < Vec < ComponentValue > > ( ) ;
265
265
let serialized = component_values. iter ( ) . to_css ( ) ;
266
266
tokenize ( serialized. as_slice ( ) ) . map ( |( c, _) | c) . collect :: < Vec < ComponentValue > > ( )
0 commit comments