8
8
// except according to those terms.
9
9
10
10
extern crate markup5ever;
11
- extern crate rustc_serialize ;
11
+ extern crate serde_json ;
12
12
extern crate rustc_test as test;
13
13
#[ macro_use]
14
14
extern crate xml5ever;
15
15
16
- use rustc_serialize :: json :: Json ;
16
+ use serde_json :: { Value , Map } ;
17
17
use std:: borrow:: Cow :: Borrowed ;
18
- use std:: collections:: BTreeMap ;
19
18
use std:: env;
19
+ use std:: io:: Read ;
20
20
use std:: ffi:: OsStr ;
21
21
use std:: mem:: replace;
22
22
use std:: path:: Path ;
@@ -151,65 +151,65 @@ trait JsonExt: Sized {
151
151
fn get_tendril ( & self ) -> StrTendril ;
152
152
fn get_nullable_tendril ( & self ) -> Option < StrTendril > ;
153
153
fn get_bool ( & self ) -> bool ;
154
- fn get_obj < ' t > ( & ' t self ) -> & ' t BTreeMap < String , Self > ;
154
+ fn get_obj < ' t > ( & ' t self ) -> & ' t Map < String , Self > ;
155
155
fn get_list < ' t > ( & ' t self ) -> & ' t Vec < Self > ;
156
156
fn find < ' t > ( & ' t self , key : & str ) -> & ' t Self ;
157
157
}
158
158
159
- impl JsonExt for Json {
159
+ impl JsonExt for Value {
160
160
fn get_str ( & self ) -> String {
161
161
match * self {
162
- Json :: String ( ref s) => s. to_string ( ) ,
163
- _ => panic ! ( "Json ::get_str: not a String" ) ,
162
+ Value :: String ( ref s) => s. to_string ( ) ,
163
+ _ => panic ! ( "Value ::get_str: not a String" ) ,
164
164
}
165
165
}
166
166
167
167
fn get_tendril ( & self ) -> StrTendril {
168
168
match * self {
169
- Json :: String ( ref s) => s. to_tendril ( ) ,
170
- _ => panic ! ( "Json ::get_tendril: not a String" ) ,
169
+ Value :: String ( ref s) => s. to_tendril ( ) ,
170
+ _ => panic ! ( "Value ::get_tendril: not a String" ) ,
171
171
}
172
172
}
173
173
174
174
fn get_nullable_tendril ( & self ) -> Option < StrTendril > {
175
175
match * self {
176
- Json :: Null => None ,
177
- Json :: String ( ref s) => Some ( s. to_tendril ( ) ) ,
178
- _ => panic ! ( "Json ::get_nullable_tendril: not a String" ) ,
176
+ Value :: Null => None ,
177
+ Value :: String ( ref s) => Some ( s. to_tendril ( ) ) ,
178
+ _ => panic ! ( "Value ::get_nullable_tendril: not a String" ) ,
179
179
}
180
180
}
181
181
182
182
fn get_bool ( & self ) -> bool {
183
183
match * self {
184
- Json :: Boolean ( b) => b,
185
- _ => panic ! ( "Json ::get_bool: not a Boolean" ) ,
184
+ Value :: Bool ( b) => b,
185
+ _ => panic ! ( "Value ::get_bool: not a Boolean" ) ,
186
186
}
187
187
}
188
188
189
- fn get_obj < ' t > ( & ' t self ) -> & ' t BTreeMap < String , Json > {
189
+ fn get_obj < ' t > ( & ' t self ) -> & ' t Map < String , Value > {
190
190
match * self {
191
- Json :: Object ( ref m) => & * m,
192
- _ => panic ! ( "Json ::get_obj: not an Object" ) ,
191
+ Value :: Object ( ref m) => & * m,
192
+ _ => panic ! ( "Value ::get_obj: not an Object" ) ,
193
193
}
194
194
}
195
195
196
- fn get_list < ' t > ( & ' t self ) -> & ' t Vec < Json > {
196
+ fn get_list < ' t > ( & ' t self ) -> & ' t Vec < Value > {
197
197
match * self {
198
- Json :: Array ( ref m) => m,
199
- _ => panic ! ( "Json ::get_list: not an Array" ) ,
198
+ Value :: Array ( ref m) => m,
199
+ _ => panic ! ( "Value ::get_list: not an Array" ) ,
200
200
}
201
201
}
202
202
203
- fn find < ' t > ( & ' t self , key : & str ) -> & ' t Json {
203
+ fn find < ' t > ( & ' t self , key : & str ) -> & ' t Value {
204
204
self . get_obj ( ) . get ( & key. to_string ( ) ) . unwrap ( )
205
205
}
206
206
}
207
207
208
208
// Parse a JSON object (other than "ParseError") to a token.
209
- fn json_to_token ( js : & Json ) -> Token {
209
+ fn json_to_token ( js : & Value ) -> Token {
210
210
let parts = js. as_array ( ) . unwrap ( ) ;
211
211
// Collect refs here so we don't have to use "ref" in all the patterns below.
212
- let args: Vec < & Json > = parts[ 1 ..] . iter ( ) . collect ( ) ;
212
+ let args: Vec < & Value > = parts[ 1 ..] . iter ( ) . collect ( ) ;
213
213
match & * parts[ 0 ] . get_str ( ) {
214
214
"StartTag" => TagToken ( Tag {
215
215
kind : StartTag ,
@@ -271,13 +271,13 @@ fn json_to_token(js: &Json) -> Token {
271
271
}
272
272
273
273
// Parse the "output" field of the test case into a vector of tokens.
274
- fn json_to_tokens ( js : & Json , exact_errors : bool ) -> Vec < Token > {
274
+ fn json_to_tokens ( js : & Value , exact_errors : bool ) -> Vec < Token > {
275
275
// Use a TokenLogger so that we combine character tokens separated
276
276
// by an ignored error.
277
277
let mut sink = TokenLogger :: new ( exact_errors) ;
278
278
for tok in js. as_array ( ) . unwrap ( ) . iter ( ) {
279
279
match * tok {
280
- Json :: String ( ref s) if & s[ ..] == "ParseError" => {
280
+ Value :: String ( ref s) if & s[ ..] == "ParseError" => {
281
281
sink. process_token ( ParseError ( Borrowed ( "" ) ) )
282
282
} ,
283
283
_ => sink. process_token ( json_to_token ( tok) ) ,
@@ -286,7 +286,7 @@ fn json_to_tokens(js: &Json, exact_errors: bool) -> Vec<Token> {
286
286
sink. get_tokens ( )
287
287
}
288
288
289
- fn mk_xml_test ( desc : String , input : String , expect : Json , opts : XmlTokenizerOpts ) -> TestDescAndFn {
289
+ fn mk_xml_test ( desc : String , input : String , expect : Value , opts : XmlTokenizerOpts ) -> TestDescAndFn {
290
290
TestDescAndFn {
291
291
desc : TestDesc :: new ( DynTestName ( desc) ) ,
292
292
testfn : DynTestFn ( Box :: new ( move || {
@@ -310,13 +310,13 @@ fn mk_xml_test(desc: String, input: String, expect: Json, opts: XmlTokenizerOpts
310
310
}
311
311
}
312
312
313
- fn mk_xml_tests ( tests : & mut Vec < TestDescAndFn > , filename : & str , js : & Json ) {
314
- let input = js. find ( "input" ) . unwrap ( ) . as_string ( ) . unwrap ( ) ;
315
- let expect = js. find ( "output" ) . unwrap ( ) . clone ( ) ;
313
+ fn mk_xml_tests ( tests : & mut Vec < TestDescAndFn > , filename : & str , js : & Value ) {
314
+ let input: & str = & js. find ( "input" ) . get_str ( ) ;
315
+ let expect = js. find ( "output" ) ;
316
316
let desc = format ! (
317
317
"tok: {}: {}" ,
318
318
filename,
319
- js. find( "description" ) . unwrap ( ) . as_string ( ) . unwrap ( )
319
+ js. find( "description" ) . get_str ( )
320
320
) ;
321
321
322
322
// Some tests want to start in a state other than Data.
@@ -360,10 +360,12 @@ fn tests(src_dir: &Path) -> Vec<TestDescAndFn> {
360
360
"tokenizer" ,
361
361
OsStr :: new ( "test" ) ,
362
362
|path, mut file| {
363
- let js = Json :: from_reader ( & mut file) . ok ( ) . expect ( "json parse error" ) ;
363
+ let mut s = String :: new ( ) ;
364
+ file. read_to_string ( & mut s) . ok ( ) . expect ( "file reading error" ) ;
365
+ let js: Value = serde_json:: from_str ( & s) . ok ( ) . expect ( "json parse error" ) ;
364
366
365
367
match js[ "tests" ] {
366
- Json :: Array ( ref lst) => {
368
+ Value :: Array ( ref lst) => {
367
369
for test in lst. iter ( ) {
368
370
mk_xml_tests (
369
371
& mut tests,
0 commit comments