]> git.lizzy.rs Git - rust.git/blob - library/alloc/tests/const_fns.rs
Update with derive_const
[rust.git] / library / alloc / tests / const_fns.rs
1 // Test const functions in the library
2
3 pub const MY_VEC: Vec<usize> = Vec::new();
4 pub const MY_VEC2: Vec<usize> = Default::default();
5
6 pub const MY_STRING: String = String::new();
7 pub const MY_STRING2: String = Default::default();
8
9 pub const MY_BOXED_SLICE: Box<[usize]> = Default::default();
10 pub const MY_BOXED_STR: Box<str> = Default::default();
11
12 use std::collections::{BTreeMap, BTreeSet};
13
14 pub const MY_BTREEMAP: BTreeMap<usize, usize> = BTreeMap::new();
15 pub const MAP: &'static BTreeMap<usize, usize> = &MY_BTREEMAP;
16 pub const MAP_LEN: usize = MAP.len();
17 pub const MAP_IS_EMPTY: bool = MAP.is_empty();
18
19 pub const MY_BTREESET: BTreeSet<usize> = BTreeSet::new();
20 pub const SET: &'static BTreeSet<usize> = &MY_BTREESET;
21 pub const SET_LEN: usize = SET.len();
22 pub const SET_IS_EMPTY: bool = SET.is_empty();
23
24 #[test]
25 fn test_const() {
26     assert_eq!(MY_VEC, MY_VEC2);
27     assert_eq!(MY_STRING, MY_STRING2);
28
29     assert_eq!(MY_VEC, *MY_BOXED_SLICE);
30     assert_eq!(MY_STRING, *MY_BOXED_STR);
31
32     assert_eq!(MAP_LEN, 0);
33     assert_eq!(SET_LEN, 0);
34     assert!(MAP_IS_EMPTY && SET_IS_EMPTY);
35 }