File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -354,7 +354,6 @@ pub fn decode_data_url(url: &str) -> Result<DecodedMap> {
354354#[ cfg( test) ]
355355mod tests {
356356 use super :: * ;
357- use crate :: jsontypes:: DebugIdField ;
358357 use std:: io:: { self , BufRead } ;
359358
360359 #[ test]
Original file line number Diff line number Diff line change @@ -230,7 +230,6 @@ impl Encodable for DecodedMap {
230230#[ cfg( test) ]
231231mod tests {
232232 use super :: * ;
233- use crate :: jsontypes:: DebugIdField ;
234233
235234 #[ test]
236235 fn test_encode_rmi ( ) {
Original file line number Diff line number Diff line change @@ -117,3 +117,46 @@ impl From<DebugIdField> for Option<DebugId> {
117117 value. value
118118 }
119119}
120+
121+ #[ cfg( test) ]
122+ mod tests {
123+ use super :: * ;
124+ use serde_json:: json;
125+
126+ fn parse_debug_id ( input : & str ) -> DebugId {
127+ input. parse ( ) . expect ( "valid debug id" )
128+ }
129+
130+ fn empty_sourcemap ( ) -> RawSourceMap {
131+ serde_json:: from_value :: < RawSourceMap > ( serde_json:: json!( { } ) )
132+ . expect ( "can deserialize empty JSON to RawSourceMap" )
133+ }
134+
135+ #[ test]
136+ fn raw_sourcemap_serializes_camel_case_debug_id ( ) {
137+ let camel = "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" ;
138+ let raw = RawSourceMap {
139+ debug_id : Some ( parse_debug_id ( camel) ) . into ( ) ,
140+ ..empty_sourcemap ( )
141+ } ;
142+
143+ let value = serde_json:: to_value ( raw) . expect ( "should serialize without error" ) ;
144+ let obj = value. as_object ( ) . expect ( "should be an object" ) ;
145+ assert ! ( obj. get( "debug_id" ) . is_none( ) ) ;
146+ assert_eq ! ( obj. get( "debugId" ) , Some ( & json!( parse_debug_id( camel) ) ) ) ;
147+ }
148+
149+ #[ test]
150+ fn raw_sourcemap_prefers_camel_case_on_deserialize ( ) {
151+ let legacy = "ffffffffffffffffffffffffffffffff" ;
152+ let camel = "00000000000000000000000000000000" ;
153+ let json = serde_json:: json!( {
154+ "debug_id" : legacy,
155+ "debugId" : camel
156+ } ) ;
157+ let raw: RawSourceMap =
158+ serde_json:: from_value ( json) . expect ( "can deserialize as RawSourceMap" ) ;
159+ let value: Option < DebugId > = raw. debug_id . into ( ) ;
160+ assert_eq ! ( value, Some ( parse_debug_id( camel) ) ) ;
161+ }
162+ }
You can’t perform that action at this time.
0 commit comments