Skip to content

Commit a943a05

Browse files
author
Oliver Schneider
committed
add unit test for non string/numeric map keys
1 parent 4d217cc commit a943a05

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libserialize/json.rs

+14
Original file line numberDiff line numberDiff line change
@@ -3817,6 +3817,20 @@ mod tests {
38173817
assert_eq!(None::<int>.to_json(), Null);
38183818
}
38193819

3820+
#[test]
3821+
fn test_encode_hashmap_with_arbitrary_key() {
3822+
use std::str::from_utf8;
3823+
use std::io::Writer;
3824+
use std::collections::HashMap;
3825+
struct ArbitraryType(uint);
3826+
let mut hm: HashMap<ArbitraryType, bool> = HashMap::new();
3827+
hm.insert(ArbitraryType(1), true);
3828+
let mut mem_buf = Vec::new();
3829+
let mut encoder = Encoder::new_compact(&mut mem_buf as &mut io::Writer);
3830+
let result = hm.encode(&mut encoder);
3831+
assert_eq!(result, BadHashmapKey);
3832+
}
3833+
38203834
#[bench]
38213835
fn bench_streaming_small(b: &mut Bencher) {
38223836
b.iter( || {

0 commit comments

Comments
 (0)