3
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
4
5
5
use std:: { str, run, task} ;
6
- use std:: rt :: io;
7
- use std:: rt :: io:: Writer ;
6
+ use std:: io;
7
+ use std:: io:: { File , Writer } ;
8
8
use extra:: { tempfile, json} ;
9
9
use extra:: json:: ToJson ;
10
10
use extra:: test;
@@ -16,7 +16,7 @@ use ast::*;
16
16
17
17
18
18
fn write_whole_file ( path : & Path , data : & str ) {
19
- match io :: file :: open ( path, io:: Create , io:: Write ) {
19
+ match File :: open_mode ( path, io:: Open , io:: Write ) {
20
20
Some ( mut writer) => writer. write ( data. as_bytes ( ) ) ,
21
21
None => fail ! ( "could not open file" ) ,
22
22
}
@@ -42,7 +42,7 @@ fn assert_json_eq(results: json::Json, expected: json::Json, message: ~str) {
42
42
let temp = tempfile::TempDir::new(" rust-cssparser-tests").unwrap();
43
43
let results = results.to_pretty_str() + "\n " ;
44
44
let expected = expected. to_pretty_str( ) + "\n " ;
45
- do task:: try {
45
+ task:: try( proc ( ) {
46
46
let mut result_path = temp. path( ) . clone( ) ;
47
47
result_path. push( "results.json" ) ;
48
48
let mut expected_path = temp. path( ) . clone( ) ;
@@ -51,14 +51,14 @@ fn assert_json_eq(results: json::Json, expected: json::Json, message: ~str) {
51
51
write_whole_file( & expected_path, expected) ;
52
52
run:: process_status( "colordiff" , [ ~"-u1000", result_path.display().to_str(),
53
53
expected_path.display().to_str()]);
54
- };
54
+ }) ;
55
55
56
56
fail!(message)
57
57
}
58
58
}
59
59
60
60
61
- fn run_raw_json_tests(json_data: &str, run: &fn ( json::Json, json::Json) ) {
61
+ fn run_raw_json_tests(json_data: &str, run: | json::Json, json::Json| ) {
62
62
let items = match json::from_str(json_data) {
63
63
Ok(json::List(items)) => items,
64
64
_ => fail!(" Invalid JSON ")
@@ -77,86 +77,86 @@ fn run_raw_json_tests(json_data: &str, run: &fn (json::Json, json::Json)) {
77
77
}
78
78
79
79
80
- fn run_json_tests<T: ToJson>(json_data: &str, parse: &fn ( input: ~str) -> T) {
81
- do run_raw_json_tests(json_data) |input, expected| {
80
+ fn run_json_tests<T: ToJson>(json_data: &str, parse: | input: ~str| -> T) {
81
+ run_raw_json_tests(json_data, |input, expected| {
82
82
match input {
83
83
json::String(input) => {
84
84
let result = parse(input.to_owned()).to_json();
85
85
assert_json_eq(result, expected, input);
86
86
},
87
87
_ => fail!(" Unexpected JSON ")
88
88
}
89
- }
89
+ });
90
90
}
91
91
92
92
93
93
#[test]
94
94
fn component_value_list() {
95
- do run_json_tests(include_str!(" css-parsing-tests/component_value_list. json")) |input| {
95
+ run_json_tests(include_str!(" css-parsing-tests/component_value_list. json"), |input| {
96
96
tokenize(input).map(|(c, _)| c).to_owned_vec()
97
- }
97
+ });
98
98
}
99
99
100
100
101
101
#[test]
102
102
fn one_component_value() {
103
- do run_json_tests(include_str!(" css-parsing-tests/one_component_value. json")) |input| {
103
+ run_json_tests(include_str!(" css-parsing-tests/one_component_value. json"), |input| {
104
104
parse_one_component_value(tokenize(input))
105
- }
105
+ });
106
106
}
107
107
108
108
109
109
#[test]
110
110
fn declaration_list() {
111
- do run_json_tests(include_str!(" css-parsing-tests/declaration_list. json")) |input| {
111
+ run_json_tests(include_str!(" css-parsing-tests/declaration_list. json"), |input| {
112
112
parse_declaration_list(tokenize(input)).to_owned_vec()
113
- }
113
+ });
114
114
}
115
115
116
116
117
117
#[test]
118
118
fn one_declaration() {
119
- do run_json_tests(include_str!(" css-parsing-tests/one_declaration. json")) |input| {
119
+ run_json_tests(include_str!(" css-parsing-tests/one_declaration. json"), |input| {
120
120
parse_one_declaration(tokenize(input))
121
- }
121
+ });
122
122
}
123
123
124
124
125
125
#[test]
126
126
fn rule_list() {
127
- do run_json_tests(include_str!(" css-parsing-tests/rule_list. json")) |input| {
127
+ run_json_tests(include_str!(" css-parsing-tests/rule_list. json"), |input| {
128
128
parse_rule_list(tokenize(input)).to_owned_vec()
129
- }
129
+ });
130
130
}
131
131
132
132
133
133
#[test]
134
134
fn stylesheet() {
135
- do run_json_tests(include_str!(" css-parsing-tests/stylesheet. json")) |input| {
135
+ run_json_tests(include_str!(" css-parsing-tests/stylesheet. json"), |input| {
136
136
parse_stylesheet_rules(tokenize(input)).to_owned_vec()
137
- }
137
+ });
138
138
}
139
139
140
140
141
141
#[test]
142
142
fn one_rule() {
143
- do run_json_tests(include_str!(" css-parsing-tests/one_rule. json")) |input| {
143
+ run_json_tests(include_str!(" css-parsing-tests/one_rule. json"), |input| {
144
144
parse_one_rule(tokenize(input))
145
- }
145
+ });
146
146
}
147
147
148
148
149
149
#[test]
150
150
fn stylesheet_from_bytes() {
151
- do run_raw_json_tests(include_str!(" css-parsing-tests/stylesheet_bytes. json"))
151
+ run_raw_json_tests(include_str!(" css-parsing-tests/stylesheet_bytes. json"),
152
152
|input, expected| {
153
153
let map = match input {
154
154
json::Object(map) => map,
155
155
_ => fail!(" Unexpected JSON ")
156
156
};
157
157
158
158
let result = {
159
- let css = get_string(map, &~" css_bytes").unwrap().iter ().map(|c| {
159
+ let css = get_string(map, &~" css_bytes").unwrap().chars ().map(|c| {
160
160
assert!(c as u32 <= 0xFF);
161
161
c as u8
162
162
}).to_owned_vec();
@@ -170,7 +170,7 @@ fn stylesheet_from_bytes() {
170
170
(rules.to_owned_vec(), used_encoding.name().to_owned()).to_json()
171
171
};
172
172
assert_json_eq(result, expected, json::Object(map).to_str());
173
- }
173
+ });
174
174
175
175
fn get_string<'a>(map: &'a json::Object, key: &~str) -> Option<&'a str> {
176
176
match map.find(key) {
@@ -183,13 +183,13 @@ fn stylesheet_from_bytes() {
183
183
}
184
184
185
185
186
- fn run_color_tests(json_data: &str, to_json: &fn( result: Option<Color>) -> json::Json) {
187
- do run_json_tests(json_data) |input| {
186
+ fn run_color_tests(json_data: &str, to_json: | result: Option<Color>| -> json::Json) {
187
+ run_json_tests(json_data, |input| {
188
188
match parse_one_component_value(tokenize(input)) {
189
189
Ok(component_value) => to_json(Color::parse(&component_value)),
190
190
Err(_reason) => json::Null,
191
191
}
192
- }
192
+ });
193
193
}
194
194
195
195
@@ -208,14 +208,14 @@ fn color3_hsl() {
208
208
/// color3_keywords.json is different: R, G and B are in 0..255 rather than 0..1
209
209
#[test]
210
210
fn color3_keywords() {
211
- do run_color_tests(include_str!(" css-parsing-tests/color3_keywords. json")) |c| {
211
+ run_color_tests(include_str!(" css-parsing-tests/color3_keywords. json"), |c| {
212
212
match c {
213
213
Some(RGBA(RGBA { red: r, green: g, blue: b, alpha: a }))
214
214
=> (~[r * 255., g * 255., b * 255., a]).to_json(),
215
215
Some(CurrentColor) => json::String(~" currentColor"),
216
216
None => json::Null,
217
217
}
218
- }
218
+ });
219
219
}
220
220
221
221
@@ -242,19 +242,19 @@ fn bench_color_lookup_fail(b: &mut test::BenchHarness) {
242
242
243
243
#[test]
244
244
fn nth() {
245
- do run_json_tests(include_str!(" css-parsing-tests/An +B . json")) |input| {
245
+ run_json_tests(include_str!(" css-parsing-tests/An +B . json"), |input| {
246
246
parse_nth(tokenize(input).map(|(c, _)| c).to_owned_vec())
247
- }
247
+ });
248
248
}
249
249
250
250
251
251
#[test]
252
252
fn serializer() {
253
- do run_json_tests(include_str!(" css-parsing-tests/component_value_list. json")) |input| {
253
+ run_json_tests(include_str!(" css-parsing-tests/component_value_list. json"), |input| {
254
254
let component_values = tokenize(input).map(|(c, _)| c).to_owned_vec();
255
255
let serialized = component_values.iter().to_css();
256
256
tokenize(serialized).map(|(c, _)| c).to_owned_vec()
257
- }
257
+ });
258
258
}
259
259
260
260
@@ -351,7 +351,7 @@ fn list_to_json(list: &~[(ComponentValue, SourceLocation)]) -> ~[json::Json] {
351
351
impl ToJson for AtRule {
352
352
fn to_json(&self) -> json::Json {
353
353
match *self {
354
- AtRule{name: ref name, prelude: ref prelude, block: ref block, _ }
354
+ AtRule{name: ref name, prelude: ref prelude, block: ref block, .. }
355
355
=> json::List(~[json::String(~" at-rule"), name.to_json(),
356
356
prelude.to_json(), block.as_ref().map(list_to_json).to_json()])
357
357
}
@@ -362,7 +362,7 @@ impl ToJson for AtRule {
362
362
impl ToJson for QualifiedRule {
363
363
fn to_json(&self) -> json::Json {
364
364
match *self {
365
- QualifiedRule{prelude: ref prelude, block: ref block, _ }
365
+ QualifiedRule{prelude: ref prelude, block: ref block, .. }
366
366
=> json::List(~[json::String(~" qualified rule"),
367
367
prelude.to_json(), json::List(list_to_json(block))])
368
368
}
@@ -373,7 +373,7 @@ impl ToJson for QualifiedRule {
373
373
impl ToJson for Declaration {
374
374
fn to_json(&self) -> json::Json {
375
375
match *self {
376
- Declaration{name: ref name, value: ref value, important: ref important, _ }
376
+ Declaration{name: ref name, value: ref value, important: ref important, .. }
377
377
=> json::List(~[json::String(~" declaration"), name.to_json(),
378
378
value.to_json(), important.to_json()])
379
379
}
0 commit comments