@@ -2583,7 +2583,7 @@ mod tests {
2583
2583
use super :: DecoderError :: * ;
2584
2584
use super :: JsonEvent :: * ;
2585
2585
use super :: { Json , from_str, DecodeResult , DecoderError , JsonEvent , Parser ,
2586
- StackElement , Stack , Decoder } ;
2586
+ StackElement , Stack , Decoder , Encoder , EncoderError } ;
2587
2587
use std:: { i64, u64, f32, f64, io} ;
2588
2588
use std:: collections:: BTreeMap ;
2589
2589
use std:: num:: Float ;
@@ -3892,6 +3892,25 @@ mod tests {
3892
3892
assert_eq ! ( None :: <int>. to_json( ) , Null ) ;
3893
3893
}
3894
3894
3895
+ #[ test]
3896
+ fn test_encode_hashmap_with_arbitrary_key ( ) {
3897
+ use std:: str:: from_utf8;
3898
+ use std:: io:: Writer ;
3899
+ use std:: collections:: HashMap ;
3900
+ use std:: fmt;
3901
+ #[ derive( PartialEq , Eq , Hash , RustcEncodable ) ]
3902
+ struct ArbitraryType ( uint ) ;
3903
+ let mut hm: HashMap < ArbitraryType , bool > = HashMap :: new ( ) ;
3904
+ hm. insert ( ArbitraryType ( 1 ) , true ) ;
3905
+ let mut mem_buf = Vec :: new ( ) ;
3906
+ let mut encoder = Encoder :: new ( & mut mem_buf as & mut fmt:: Writer ) ;
3907
+ let result = hm. encode ( & mut encoder) ;
3908
+ match result. unwrap_err ( ) {
3909
+ EncoderError :: BadHashmapKey => ( ) ,
3910
+ _ => panic ! ( "expected bad hash map key" )
3911
+ }
3912
+ }
3913
+
3895
3914
#[ bench]
3896
3915
fn bench_streaming_small ( b : & mut Bencher ) {
3897
3916
b. iter ( || {
0 commit comments