]> git.lizzy.rs Git - rust.git/blob - src/liballoc/tests/lib.rs
a76fd87a1a92da5bd3b5a523bf49b86c742245d1
[rust.git] / src / liballoc / tests / lib.rs
1 #![feature(allocator_api)]
2 #![feature(box_syntax)]
3 #![feature(drain_filter)]
4 #![feature(exact_size_is_empty)]
5 #![feature(pattern)]
6 #![feature(repeat_generic_slice)]
7 #![feature(slice_sort_by_cached_key)]
8 #![feature(str_escape)]
9 #![feature(try_reserve)]
10 #![feature(unboxed_closures)]
11 #![feature(vecdeque_rotate)]
12
13 extern crate core;
14 extern crate rand;
15
16 use std::hash::{Hash, Hasher};
17 use std::collections::hash_map::DefaultHasher;
18
19 mod arc;
20 mod binary_heap;
21 mod btree;
22 mod cow_str;
23 mod fmt;
24 mod heap;
25 mod linked_list;
26 mod rc;
27 mod slice;
28 mod str;
29 mod string;
30 mod vec_deque;
31 mod vec;
32
33 fn hash<T: Hash>(t: &T) -> u64 {
34     let mut s = DefaultHasher::new();
35     t.hash(&mut s);
36     s.finish()
37 }
38
39 // FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
40 // See https://github.com/kripken/emscripten-fastcomp/issues/169
41 #[cfg(not(target_os = "emscripten"))]
42 #[test]
43 fn test_boxed_hasher() {
44     let ordinary_hash = hash(&5u32);
45
46     let mut hasher_1 = Box::new(DefaultHasher::new());
47     5u32.hash(&mut hasher_1);
48     assert_eq!(ordinary_hash, hasher_1.finish());
49
50     let mut hasher_2 = Box::new(DefaultHasher::new()) as Box<dyn Hasher>;
51     5u32.hash(&mut hasher_2);
52     assert_eq!(ordinary_hash, hasher_2.finish());
53 }