use super::DecoderError::*;
use super::JsonEvent::*;
use super::{Json, from_str, DecodeResult, DecoderError, JsonEvent, Parser,
- StackElement, Stack, Decoder};
+ StackElement, Stack, Decoder, Encoder, EncoderError};
use std::{i64, u64, f32, f64, io};
use std::collections::BTreeMap;
use std::num::Float;
assert_eq!(None::<int>.to_json(), Null);
}
+ #[test]
+ fn test_encode_hashmap_with_arbitrary_key() {
+ use std::str::from_utf8;
+ use std::io::Writer;
+ use std::collections::HashMap;
+ use std::fmt;
+ #[derive(PartialEq, Eq, Hash, RustcEncodable)]
+ struct ArbitraryType(uint);
+ let mut hm: HashMap<ArbitraryType, bool> = HashMap::new();
+ hm.insert(ArbitraryType(1), true);
+ let mut mem_buf = Vec::new();
+ let mut encoder = Encoder::new(&mut mem_buf as &mut fmt::Writer);
+ let result = hm.encode(&mut encoder);
+ match result.unwrap_err() {
+ EncoderError::BadHashmapKey => (),
+ _ => panic!("expected bad hash map key")
+ }
+ }
+
#[bench]
fn bench_streaming_small(b: &mut Bencher) {
b.iter( || {