33 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44
55use 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 } ;
88use extra:: { tempfile, json} ;
99use extra:: json:: ToJson ;
1010use extra:: test;
@@ -16,7 +16,7 @@ use ast::*;
1616
1717
1818fn 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 ) {
2020 Some ( mut writer) => writer. write ( data. as_bytes ( ) ) ,
2121 None => fail ! ( "could not open file" ) ,
2222 }
@@ -42,7 +42,7 @@ fn assert_json_eq(results: json::Json, expected: json::Json, message: ~str) {
4242 let temp = tempfile::TempDir::new(" rust-cssparser-tests").unwrap();
4343 let results = results.to_pretty_str() + "\n " ;
4444 let expected = expected. to_pretty_str( ) + "\n " ;
45- do task:: try {
45+ task:: try( proc ( ) {
4646 let mut result_path = temp. path( ) . clone( ) ;
4747 result_path. push( "results.json" ) ;
4848 let mut expected_path = temp. path( ) . clone( ) ;
@@ -51,14 +51,14 @@ fn assert_json_eq(results: json::Json, expected: json::Json, message: ~str) {
5151 write_whole_file( & expected_path, expected) ;
5252 run:: process_status( "colordiff" , [ ~"-u1000", result_path.display().to_str(),
5353 expected_path.display().to_str()]);
54- };
54+ }) ;
5555
5656 fail!(message)
5757 }
5858}
5959
6060
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| ) {
6262 let items = match json::from_str(json_data) {
6363 Ok(json::List(items)) => items,
6464 _ => fail!(" Invalid JSON ")
@@ -77,86 +77,86 @@ fn run_raw_json_tests(json_data: &str, run: &fn (json::Json, json::Json)) {
7777}
7878
7979
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| {
8282 match input {
8383 json::String(input) => {
8484 let result = parse(input.to_owned()).to_json();
8585 assert_json_eq(result, expected, input);
8686 },
8787 _ => fail!(" Unexpected JSON ")
8888 }
89- }
89+ });
9090}
9191
9292
9393#[test]
9494fn 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| {
9696 tokenize(input).map(|(c, _)| c).to_owned_vec()
97- }
97+ });
9898}
9999
100100
101101#[test]
102102fn 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| {
104104 parse_one_component_value(tokenize(input))
105- }
105+ });
106106}
107107
108108
109109#[test]
110110fn 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| {
112112 parse_declaration_list(tokenize(input)).to_owned_vec()
113- }
113+ });
114114}
115115
116116
117117#[test]
118118fn 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| {
120120 parse_one_declaration(tokenize(input))
121- }
121+ });
122122}
123123
124124
125125#[test]
126126fn 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| {
128128 parse_rule_list(tokenize(input)).to_owned_vec()
129- }
129+ });
130130}
131131
132132
133133#[test]
134134fn 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| {
136136 parse_stylesheet_rules(tokenize(input)).to_owned_vec()
137- }
137+ });
138138}
139139
140140
141141#[test]
142142fn 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| {
144144 parse_one_rule(tokenize(input))
145- }
145+ });
146146}
147147
148148
149149#[test]
150150fn 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"),
152152 |input, expected| {
153153 let map = match input {
154154 json::Object(map) => map,
155155 _ => fail!(" Unexpected JSON ")
156156 };
157157
158158 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| {
160160 assert!(c as u32 <= 0xFF);
161161 c as u8
162162 }).to_owned_vec();
@@ -170,7 +170,7 @@ fn stylesheet_from_bytes() {
170170 (rules.to_owned_vec(), used_encoding.name().to_owned()).to_json()
171171 };
172172 assert_json_eq(result, expected, json::Object(map).to_str());
173- }
173+ });
174174
175175 fn get_string<'a>(map: &'a json::Object, key: &~str) -> Option<&'a str> {
176176 match map.find(key) {
@@ -183,13 +183,13 @@ fn stylesheet_from_bytes() {
183183}
184184
185185
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| {
188188 match parse_one_component_value(tokenize(input)) {
189189 Ok(component_value) => to_json(Color::parse(&component_value)),
190190 Err(_reason) => json::Null,
191191 }
192- }
192+ });
193193}
194194
195195
@@ -208,14 +208,14 @@ fn color3_hsl() {
208208/// color3_keywords.json is different: R, G and B are in 0..255 rather than 0..1
209209#[test]
210210fn 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| {
212212 match c {
213213 Some(RGBA(RGBA { red: r, green: g, blue: b, alpha: a }))
214214 => (~[r * 255., g * 255., b * 255., a]).to_json(),
215215 Some(CurrentColor) => json::String(~" currentColor"),
216216 None => json::Null,
217217 }
218- }
218+ });
219219}
220220
221221
@@ -242,19 +242,19 @@ fn bench_color_lookup_fail(b: &mut test::BenchHarness) {
242242
243243#[test]
244244fn 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| {
246246 parse_nth(tokenize(input).map(|(c, _)| c).to_owned_vec())
247- }
247+ });
248248}
249249
250250
251251#[test]
252252fn 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| {
254254 let component_values = tokenize(input).map(|(c, _)| c).to_owned_vec();
255255 let serialized = component_values.iter().to_css();
256256 tokenize(serialized).map(|(c, _)| c).to_owned_vec()
257- }
257+ });
258258}
259259
260260
@@ -351,7 +351,7 @@ fn list_to_json(list: &~[(ComponentValue, SourceLocation)]) -> ~[json::Json] {
351351impl ToJson for AtRule {
352352 fn to_json(&self) -> json::Json {
353353 match *self {
354- AtRule{name: ref name, prelude: ref prelude, block: ref block, _ }
354+ AtRule{name: ref name, prelude: ref prelude, block: ref block, .. }
355355 => json::List(~[json::String(~" at-rule"), name.to_json(),
356356 prelude.to_json(), block.as_ref().map(list_to_json).to_json()])
357357 }
@@ -362,7 +362,7 @@ impl ToJson for AtRule {
362362impl ToJson for QualifiedRule {
363363 fn to_json(&self) -> json::Json {
364364 match *self {
365- QualifiedRule{prelude: ref prelude, block: ref block, _ }
365+ QualifiedRule{prelude: ref prelude, block: ref block, .. }
366366 => json::List(~[json::String(~" qualified rule"),
367367 prelude.to_json(), json::List(list_to_json(block))])
368368 }
@@ -373,7 +373,7 @@ impl ToJson for QualifiedRule {
373373impl ToJson for Declaration {
374374 fn to_json(&self) -> json::Json {
375375 match *self {
376- Declaration{name: ref name, value: ref value, important: ref important, _ }
376+ Declaration{name: ref name, value: ref value, important: ref important, .. }
377377 => json::List(~[json::String(~" declaration"), name.to_json(),
378378 value.to_json(), important.to_json()])
379379 }
0 commit comments