1 use wasmtime::Result; 2 use wasmtime_environ::collections::{TryClone, TryHashMap}; 3 use wasmtime_fuzzing::oom::OomTest; 4 5 #[test] try_hash_map_with_capacity() -> Result<()>6fn try_hash_map_with_capacity() -> Result<()> { 7 OomTest::new().test(|| { 8 let _s = TryHashMap::<usize, usize>::with_capacity(100)?; 9 Ok(()) 10 }) 11 } 12 13 #[test] try_hash_map_reserve() -> Result<()>14fn try_hash_map_reserve() -> Result<()> { 15 OomTest::new().test(|| { 16 let mut map = TryHashMap::<usize, usize>::new(); 17 map.reserve(100)?; 18 Ok(()) 19 }) 20 } 21 22 #[test] try_hash_map_insert() -> Result<()>23fn try_hash_map_insert() -> Result<()> { 24 OomTest::new().test(|| { 25 let mut map = TryHashMap::<usize, usize>::new(); 26 for i in 0..1024 { 27 map.insert(i, i * 2)?; 28 } 29 for i in 0..1024 { 30 map.insert(i, i * 2)?; 31 } 32 Ok(()) 33 }) 34 } 35 36 #[test] try_hash_map_try_clone() -> Result<()>37fn try_hash_map_try_clone() -> Result<()> { 38 OomTest::new().test(|| { 39 let mut map = TryHashMap::new(); 40 for i in 0..10 { 41 map.insert(i, i * 2)?; 42 } 43 let map2 = map.try_clone()?; 44 assert_eq!(map, map2); 45 Ok(()) 46 }) 47 } 48