Skip to content

Commit

Permalink
add unit test for non string/numeric map keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver 'ker' Schneider authored and Oliver Schneider committed Jan 19, 2015
1 parent d727f99 commit 0478a8c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/libserialize/json.rs
Expand Up @@ -2583,7 +2583,7 @@ mod tests {
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;
Expand Down Expand Up @@ -3892,6 +3892,25 @@ mod tests {
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( || {
Expand Down

0 comments on commit 0478a8c

Please sign in to comment.