add unit test for non string/numeric map keys
This commit is contained in:
parent
d727f99107
commit
0478a8c1d7
1 changed files with 20 additions and 1 deletions
|
@ -2583,7 +2583,7 @@ mod tests {
|
||||||
use super::DecoderError::*;
|
use super::DecoderError::*;
|
||||||
use super::JsonEvent::*;
|
use super::JsonEvent::*;
|
||||||
use super::{Json, from_str, DecodeResult, DecoderError, JsonEvent, Parser,
|
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::{i64, u64, f32, f64, io};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::num::Float;
|
use std::num::Float;
|
||||||
|
@ -3892,6 +3892,25 @@ mod tests {
|
||||||
assert_eq!(None::<int>.to_json(), Null);
|
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]
|
#[bench]
|
||||||
fn bench_streaming_small(b: &mut Bencher) {
|
fn bench_streaming_small(b: &mut Bencher) {
|
||||||
b.iter( || {
|
b.iter( || {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue