88// except according to those terms.
99
1010extern crate markup5ever;
11- extern crate rustc_serialize ;
11+ extern crate serde_json ;
1212extern crate rustc_test as test;
1313#[ macro_use]
1414extern crate xml5ever;
1515
16- use rustc_serialize :: json :: Json ;
16+ use serde_json :: { Value , Map } ;
1717use std:: borrow:: Cow :: Borrowed ;
18- use std:: collections:: BTreeMap ;
1918use std:: env;
19+ use std:: io:: Read ;
2020use std:: ffi:: OsStr ;
2121use std:: mem:: replace;
2222use std:: path:: Path ;
@@ -151,65 +151,65 @@ trait JsonExt: Sized {
151151 fn get_tendril ( & self ) -> StrTendril ;
152152 fn get_nullable_tendril ( & self ) -> Option < StrTendril > ;
153153 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 > ;
155155 fn get_list < ' t > ( & ' t self ) -> & ' t Vec < Self > ;
156156 fn find < ' t > ( & ' t self , key : & str ) -> & ' t Self ;
157157}
158158
159- impl JsonExt for Json {
159+ impl JsonExt for Value {
160160 fn get_str ( & self ) -> String {
161161 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" ) ,
164164 }
165165 }
166166
167167 fn get_tendril ( & self ) -> StrTendril {
168168 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" ) ,
171171 }
172172 }
173173
174174 fn get_nullable_tendril ( & self ) -> Option < StrTendril > {
175175 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" ) ,
179179 }
180180 }
181181
182182 fn get_bool ( & self ) -> bool {
183183 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" ) ,
186186 }
187187 }
188188
189- fn get_obj < ' t > ( & ' t self ) -> & ' t BTreeMap < String , Json > {
189+ fn get_obj < ' t > ( & ' t self ) -> & ' t Map < String , Value > {
190190 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" ) ,
193193 }
194194 }
195195
196- fn get_list < ' t > ( & ' t self ) -> & ' t Vec < Json > {
196+ fn get_list < ' t > ( & ' t self ) -> & ' t Vec < Value > {
197197 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" ) ,
200200 }
201201 }
202202
203- fn find < ' t > ( & ' t self , key : & str ) -> & ' t Json {
203+ fn find < ' t > ( & ' t self , key : & str ) -> & ' t Value {
204204 self . get_obj ( ) . get ( & key. to_string ( ) ) . unwrap ( )
205205 }
206206}
207207
208208// 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 {
210210 let parts = js. as_array ( ) . unwrap ( ) ;
211211 // 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 ( ) ;
213213 match & * parts[ 0 ] . get_str ( ) {
214214 "StartTag" => TagToken ( Tag {
215215 kind : StartTag ,
@@ -271,13 +271,13 @@ fn json_to_token(js: &Json) -> Token {
271271}
272272
273273// 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 > {
275275 // Use a TokenLogger so that we combine character tokens separated
276276 // by an ignored error.
277277 let mut sink = TokenLogger :: new ( exact_errors) ;
278278 for tok in js. as_array ( ) . unwrap ( ) . iter ( ) {
279279 match * tok {
280- Json :: String ( ref s) if & s[ ..] == "ParseError" => {
280+ Value :: String ( ref s) if & s[ ..] == "ParseError" => {
281281 sink. process_token ( ParseError ( Borrowed ( "" ) ) )
282282 } ,
283283 _ => sink. process_token ( json_to_token ( tok) ) ,
@@ -286,7 +286,7 @@ fn json_to_tokens(js: &Json, exact_errors: bool) -> Vec<Token> {
286286 sink. get_tokens ( )
287287}
288288
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 {
290290 TestDescAndFn {
291291 desc : TestDesc :: new ( DynTestName ( desc) ) ,
292292 testfn : DynTestFn ( Box :: new ( move || {
@@ -310,13 +310,13 @@ fn mk_xml_test(desc: String, input: String, expect: Json, opts: XmlTokenizerOpts
310310 }
311311}
312312
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" ) ;
316316 let desc = format ! (
317317 "tok: {}: {}" ,
318318 filename,
319- js. find( "description" ) . unwrap ( ) . as_string ( ) . unwrap ( )
319+ js. find( "description" ) . get_str ( )
320320 ) ;
321321
322322 // Some tests want to start in a state other than Data.
@@ -360,10 +360,12 @@ fn tests(src_dir: &Path) -> Vec<TestDescAndFn> {
360360 "tokenizer" ,
361361 OsStr :: new ( "test" ) ,
362362 |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" ) ;
364366
365367 match js[ "tests" ] {
366- Json :: Array ( ref lst) => {
368+ Value :: Array ( ref lst) => {
367369 for test in lst. iter ( ) {
368370 mk_xml_tests (
369371 & mut tests,
0 commit comments