]> git.lizzy.rs Git - rust.git/blob - library/alloc/tests/const_fns.rs
Rollup merge of #92231 - ehuss:update-books, r=ehuss
[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 use std::collections::{BTreeMap, BTreeSet};
10
11 pub const MY_BTREEMAP: BTreeMap<usize, usize> = BTreeMap::new();
12 pub const MAP: &'static BTreeMap<usize, usize> = &MY_BTREEMAP;
13 pub const MAP_LEN: usize = MAP.len();
14 pub const MAP_IS_EMPTY: bool = MAP.is_empty();
15
16 pub const MY_BTREESET: BTreeSet<usize> = BTreeSet::new();
17 pub const SET: &'static BTreeSet<usize> = &MY_BTREESET;
18 pub const SET_LEN: usize = SET.len();
19 pub const SET_IS_EMPTY: bool = SET.is_empty();
20
21 #[test]
22 fn test_const() {
23     assert_eq!(MY_VEC, MY_VEC2);
24     assert_eq!(MY_STRING, MY_STRING2);
25
26     assert_eq!(MAP_LEN, 0);
27     assert_eq!(SET_LEN, 0);
28     assert!(MAP_IS_EMPTY && SET_IS_EMPTY);
29 }