]> git.lizzy.rs Git - rust.git/blob - src/liballoc/tests/lib.rs
Rollup merge of #55469 - pnkfelix:issue-54477-regression-tests, r=nikomatsakis
[rust.git] / src / liballoc / tests / lib.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(allocator_api)]
12 #![feature(alloc_system)]
13 #![feature(box_syntax)]
14 #![feature(drain_filter)]
15 #![feature(exact_size_is_empty)]
16 #![feature(pattern)]
17 #![feature(slice_sort_by_cached_key)]
18 #![feature(str_escape)]
19 #![feature(try_reserve)]
20 #![feature(unboxed_closures)]
21 #![feature(repeat_generic_slice)]
22
23 extern crate alloc_system;
24 extern crate core;
25 extern crate rand;
26
27 use std::hash::{Hash, Hasher};
28 use std::collections::hash_map::DefaultHasher;
29
30 mod arc;
31 mod binary_heap;
32 mod btree;
33 mod cow_str;
34 mod fmt;
35 mod heap;
36 mod linked_list;
37 mod rc;
38 mod slice;
39 mod str;
40 mod string;
41 mod vec_deque;
42 mod vec;
43
44 fn hash<T: Hash>(t: &T) -> u64 {
45     let mut s = DefaultHasher::new();
46     t.hash(&mut s);
47     s.finish()
48 }
49
50 // FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
51 // See https://github.com/kripken/emscripten-fastcomp/issues/169
52 #[cfg(not(target_os = "emscripten"))]
53 #[test]
54 fn test_boxed_hasher() {
55     let ordinary_hash = hash(&5u32);
56
57     let mut hasher_1 = Box::new(DefaultHasher::new());
58     5u32.hash(&mut hasher_1);
59     assert_eq!(ordinary_hash, hasher_1.finish());
60
61     let mut hasher_2 = Box::new(DefaultHasher::new()) as Box<dyn Hasher>;
62     5u32.hash(&mut hasher_2);
63     assert_eq!(ordinary_hash, hasher_2.finish());
64 }