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