77// option. This file may not be copied, modified, or distributed
88// except according to those terms.
99
10- extern crate rustc_serialize ;
10+ extern crate serde_json ;
1111extern crate rustc_test as test;
1212#[ macro_use]
1313extern crate html5ever;
1414
1515mod foreach_html5lib_test;
1616use foreach_html5lib_test:: foreach_html5lib_test;
1717
18- use rustc_serialize :: json :: Json ;
18+ use serde_json :: { Value , Map } ;
1919use std:: borrow:: Cow :: Borrowed ;
20- use std:: collections:: BTreeMap ;
2120use std:: default:: Default ;
2221use std:: ffi:: OsStr ;
22+ use std:: io:: Read ;
2323use std:: mem:: replace;
2424use std:: path:: Path ;
2525use std:: { char, env} ;
@@ -152,65 +152,65 @@ trait JsonExt: Sized {
152152 fn get_tendril ( & self ) -> StrTendril ;
153153 fn get_nullable_tendril ( & self ) -> Option < StrTendril > ;
154154 fn get_bool ( & self ) -> bool ;
155- fn get_obj < ' t > ( & ' t self ) -> & ' t BTreeMap < String , Self > ;
155+ fn get_obj < ' t > ( & ' t self ) -> & ' t Map < String , Self > ;
156156 fn get_list < ' t > ( & ' t self ) -> & ' t Vec < Self > ;
157157 fn find < ' t > ( & ' t self , key : & str ) -> & ' t Self ;
158158}
159159
160- impl JsonExt for Json {
160+ impl JsonExt for Value {
161161 fn get_str ( & self ) -> String {
162162 match * self {
163- Json :: String ( ref s) => s. to_string ( ) ,
164- _ => panic ! ( "Json ::get_str: not a String" ) ,
163+ Value :: String ( ref s) => s. to_string ( ) ,
164+ _ => panic ! ( "Value ::get_str: not a String" ) ,
165165 }
166166 }
167167
168168 fn get_tendril ( & self ) -> StrTendril {
169169 match * self {
170- Json :: String ( ref s) => s. to_tendril ( ) ,
171- _ => panic ! ( "Json ::get_tendril: not a String" ) ,
170+ Value :: String ( ref s) => s. to_tendril ( ) ,
171+ _ => panic ! ( "Value ::get_tendril: not a String" ) ,
172172 }
173173 }
174174
175175 fn get_nullable_tendril ( & self ) -> Option < StrTendril > {
176176 match * self {
177- Json :: Null => None ,
178- Json :: String ( ref s) => Some ( s. to_tendril ( ) ) ,
179- _ => panic ! ( "Json ::get_nullable_tendril: not a String" ) ,
177+ Value :: Null => None ,
178+ Value :: String ( ref s) => Some ( s. to_tendril ( ) ) ,
179+ _ => panic ! ( "Value ::get_nullable_tendril: not a String" ) ,
180180 }
181181 }
182182
183183 fn get_bool ( & self ) -> bool {
184184 match * self {
185- Json :: Boolean ( b) => b,
186- _ => panic ! ( "Json ::get_bool: not a Boolean " ) ,
185+ Value :: Bool ( b) => b,
186+ _ => panic ! ( "Value ::get_bool: not a Bool " ) ,
187187 }
188188 }
189189
190- fn get_obj < ' t > ( & ' t self ) -> & ' t BTreeMap < String , Json > {
190+ fn get_obj < ' t > ( & ' t self ) -> & ' t Map < String , Value > {
191191 match * self {
192- Json :: Object ( ref m) => & * m,
193- _ => panic ! ( "Json ::get_obj: not an Object" ) ,
192+ Value :: Object ( ref m) => & * m,
193+ _ => panic ! ( "Value ::get_obj: not an Object" ) ,
194194 }
195195 }
196196
197- fn get_list < ' t > ( & ' t self ) -> & ' t Vec < Json > {
197+ fn get_list < ' t > ( & ' t self ) -> & ' t Vec < Value > {
198198 match * self {
199- Json :: Array ( ref m) => m,
200- _ => panic ! ( "Json ::get_list: not an Array" ) ,
199+ Value :: Array ( ref m) => m,
200+ _ => panic ! ( "Value ::get_list: not an Array" ) ,
201201 }
202202 }
203203
204- fn find < ' t > ( & ' t self , key : & str ) -> & ' t Json {
204+ fn find < ' t > ( & ' t self , key : & str ) -> & ' t Value {
205205 self . get_obj ( ) . get ( & key. to_string ( ) ) . unwrap ( )
206206 }
207207}
208208
209209// Parse a JSON object (other than "ParseError") to a token.
210- fn json_to_token ( js : & Json ) -> Token {
210+ fn json_to_token ( js : & Value ) -> Token {
211211 let parts = js. get_list ( ) ;
212212 // Collect refs here so we don't have to use "ref" in all the patterns below.
213- let args: Vec < & Json > = parts[ 1 ..] . iter ( ) . collect ( ) ;
213+ let args: Vec < & Value > = parts[ 1 ..] . iter ( ) . collect ( ) ;
214214 match & * parts[ 0 ] . get_str ( ) {
215215 "DOCTYPE" => DoctypeToken ( Doctype {
216216 name : args[ 0 ] . get_nullable_tendril ( ) ,
@@ -254,14 +254,14 @@ fn json_to_token(js: &Json) -> Token {
254254}
255255
256256// Parse the "output" field of the test case into a vector of tokens.
257- fn json_to_tokens ( js : & Json , exact_errors : bool ) -> Vec < Token > {
257+ fn json_to_tokens ( js : & Value , exact_errors : bool ) -> Vec < Token > {
258258 // Use a TokenLogger so that we combine character tokens separated
259259 // by an ignored error.
260260 let mut sink = TokenLogger :: new ( exact_errors) ;
261261 for tok in js. get_list ( ) . iter ( ) {
262262 assert_eq ! (
263263 match * tok {
264- Json :: String ( ref s) if & s[ ..] == "ParseError" => {
264+ Value :: String ( ref s) if & s[ ..] == "ParseError" => {
265265 sink. process_token( ParseError ( Borrowed ( "" ) ) , 0 )
266266 } ,
267267 _ => sink. process_token( json_to_token( tok) , 0 ) ,
@@ -299,24 +299,24 @@ fn unescape(s: &str) -> Option<String> {
299299 }
300300}
301301
302- fn unescape_json ( js : & Json ) -> Json {
302+ fn unescape_json ( js : & Value ) -> Value {
303303 match * js {
304304 // unwrap is OK here because the spec'd *output* of the tokenizer never
305305 // contains a lone surrogate.
306- Json :: String ( ref s) => Json :: String ( unescape ( & s) . unwrap ( ) ) ,
307- Json :: Array ( ref xs) => Json :: Array ( xs. iter ( ) . map ( unescape_json) . collect ( ) ) ,
308- Json :: Object ( ref obj) => {
309- let mut new_obj = BTreeMap :: new ( ) ;
306+ Value :: String ( ref s) => Value :: String ( unescape ( & s) . unwrap ( ) ) ,
307+ Value :: Array ( ref xs) => Value :: Array ( xs. iter ( ) . map ( unescape_json) . collect ( ) ) ,
308+ Value :: Object ( ref obj) => {
309+ let mut new_obj = Map :: new ( ) ;
310310 for ( k, v) in obj. iter ( ) {
311311 new_obj. insert ( k. clone ( ) , unescape_json ( v) ) ;
312312 }
313- Json :: Object ( new_obj)
313+ Value :: Object ( new_obj)
314314 } ,
315315 _ => js. clone ( ) ,
316316 }
317317}
318318
319- fn mk_test ( desc : String , input : String , expect : Json , opts : TokenizerOpts ) -> TestDescAndFn {
319+ fn mk_test ( desc : String , input : String , expect : Value , opts : TokenizerOpts ) -> TestDescAndFn {
320320 TestDescAndFn {
321321 desc : TestDesc :: new ( DynTestName ( desc) ) ,
322322 testfn : DynTestFn ( Box :: new ( move || {
@@ -340,14 +340,14 @@ fn mk_test(desc: String, input: String, expect: Json, opts: TokenizerOpts) -> Te
340340 }
341341}
342342
343- fn mk_tests ( tests : & mut Vec < TestDescAndFn > , filename : & str , js : & Json ) {
343+ fn mk_tests ( tests : & mut Vec < TestDescAndFn > , filename : & str , js : & Value ) {
344344 let obj = js. get_obj ( ) ;
345- let mut input = js. find ( "input" ) . unwrap ( ) . get_str ( ) ;
346- let mut expect = js. find ( "output" ) . unwrap ( ) . clone ( ) ;
345+ let mut input = js. find ( "input" ) . get_str ( ) ;
346+ let mut expect = js. find ( "output" ) . clone ( ) ;
347347 let desc = format ! (
348348 "tok: {}: {}" ,
349349 filename,
350- js. find( "description" ) . unwrap ( ) . get_str( )
350+ js. find( "description" ) . get_str( )
351351 ) ;
352352
353353 // "Double-escaped" tests require additional processing of
@@ -368,7 +368,7 @@ fn mk_tests(tests: &mut Vec<TestDescAndFn>, filename: &str, js: &Json) {
368368
369369 // Some tests want to start in a state other than Data.
370370 let state_overrides = match obj. get ( & "initialStates" . to_string ( ) ) {
371- Some ( & Json :: Array ( ref xs) ) => xs
371+ Some ( & Value :: Array ( ref xs) ) => xs
372372 . iter ( )
373373 . map ( |s| {
374374 Some ( match & s. get_str ( ) [ ..] {
@@ -423,10 +423,12 @@ fn tests(src_dir: &Path) -> Vec<TestDescAndFn> {
423423 "tokenizer" ,
424424 OsStr :: new ( "test" ) ,
425425 |path, mut file| {
426- let js = Json :: from_reader ( & mut file) . ok ( ) . expect ( "json parse error" ) ;
426+ let mut s = String :: new ( ) ;
427+ file. read_to_string ( & mut s) . ok ( ) . expect ( "file reading error" ) ;
428+ let js: Value = serde_json:: from_str ( & s) . ok ( ) . expect ( "json parse error" ) ;
427429
428430 match js. get_obj ( ) . get ( & "tests" . to_string ( ) ) {
429- Some ( & Json :: Array ( ref lst) ) => {
431+ Some ( & Value :: Array ( ref lst) ) => {
430432 for test in lst. iter ( ) {
431433 mk_tests (
432434 & mut tests,
0 commit comments