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