]> git.lizzy.rs Git - rust.git/blob - src/liballoc/tests/lib.rs
Rollup merge of #53110 - Xanewok:save-analysis-remap-path, r=nrc
[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(attr_literals)]
14 #![feature(box_syntax)]
15 #![feature(const_fn)]
16 #![feature(drain_filter)]
17 #![feature(exact_size_is_empty)]
18 #![feature(pattern)]
19 #![feature(slice_sort_by_cached_key)]
20 #![feature(str_escape)]
21 #![feature(try_reserve)]
22 #![feature(unboxed_closures)]
23 #![feature(exact_chunks)]
24 #![feature(repeat_generic_slice)]
25
26 extern crate alloc_system;
27 extern crate core;
28 extern crate rand;
29
30 use std::hash::{Hash, Hasher};
31 use std::collections::hash_map::DefaultHasher;
32
33 mod arc;
34 mod binary_heap;
35 mod btree;
36 mod cow_str;
37 mod fmt;
38 mod heap;
39 mod linked_list;
40 mod rc;
41 mod slice;
42 mod str;
43 mod string;
44 mod vec_deque;
45 mod vec;
46
47 fn hash<T: Hash>(t: &T) -> u64 {
48     let mut s = DefaultHasher::new();
49     t.hash(&mut s);
50     s.finish()
51 }
52
53 // FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
54 // See https://github.com/kripken/emscripten-fastcomp/issues/169
55 #[cfg(not(target_os = "emscripten"))]
56 #[test]
57 fn test_boxed_hasher() {
58     let ordinary_hash = hash(&5u32);
59
60     let mut hasher_1 = Box::new(DefaultHasher::new());
61     5u32.hash(&mut hasher_1);
62     assert_eq!(ordinary_hash, hasher_1.finish());
63
64     let mut hasher_2 = Box::new(DefaultHasher::new()) as Box<dyn Hasher>;
65     5u32.hash(&mut hasher_2);
66     assert_eq!(ordinary_hash, hasher_2.finish());
67 }