]> git.lizzy.rs Git - rust.git/blob - library/alloc/tests/lib.rs
3ee0cfbe74759862a6da591141abb1b85a931808
[rust.git] / library / alloc / tests / lib.rs
1 #![feature(allocator_api)]
2 #![feature(box_syntax)]
3 #![feature(cow_is_borrowed)]
4 #![feature(drain_filter)]
5 #![feature(exact_size_is_empty)]
6 #![feature(new_uninit)]
7 #![feature(pattern)]
8 #![feature(str_split_once)]
9 #![feature(trusted_len)]
10 #![feature(try_reserve)]
11 #![feature(unboxed_closures)]
12 #![feature(associated_type_bounds)]
13 #![feature(binary_heap_into_iter_sorted)]
14 #![feature(binary_heap_drain_sorted)]
15 #![feature(slice_ptr_get)]
16 #![feature(split_inclusive)]
17 #![feature(binary_heap_retain)]
18 #![feature(deque_range)]
19 #![feature(inplace_iteration)]
20 #![feature(iter_map_while)]
21 #![feature(int_bits_const)]
22
23 use std::collections::hash_map::DefaultHasher;
24 use std::hash::{Hash, Hasher};
25
26 mod arc;
27 mod binary_heap;
28 mod borrow;
29 mod boxed;
30 mod btree_set_hash;
31 mod cow_str;
32 mod fmt;
33 mod heap;
34 mod linked_list;
35 mod rc;
36 mod slice;
37 mod str;
38 mod string;
39 mod vec;
40 mod vec_deque;
41
42 fn hash<T: Hash>(t: &T) -> u64 {
43     let mut s = DefaultHasher::new();
44     t.hash(&mut s);
45     s.finish()
46 }
47
48 // FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
49 // See https://github.com/kripken/emscripten-fastcomp/issues/169
50 #[cfg(not(target_os = "emscripten"))]
51 #[test]
52 fn test_boxed_hasher() {
53     let ordinary_hash = hash(&5u32);
54
55     let mut hasher_1 = Box::new(DefaultHasher::new());
56     5u32.hash(&mut hasher_1);
57     assert_eq!(ordinary_hash, hasher_1.finish());
58
59     let mut hasher_2 = Box::new(DefaultHasher::new()) as Box<dyn Hasher>;
60     5u32.hash(&mut hasher_2);
61     assert_eq!(ordinary_hash, hasher_2.finish());
62 }