use tlid::{AllocError, Checked, CheckedError, Pool}; #[test] fn print_checked_error() { let mut pool = Pool::>::new(1..2); assert_eq!(pool.next(), Ok(1)); assert_eq!(pool.next(), Err(CheckedError::PoolEmpty)); assert_eq!( format!("{}", pool.next().unwrap_err()), "pool is empty, all Id's are used up" ); } #[test] fn source_checked_error() { let mut pool = Pool::>::new(1..2); assert_eq!(pool.next(), Ok(1)); let sp = pool.next(); let e: &dyn std::error::Error = &sp.unwrap_err(); assert!(e.source().is_none()); } #[test] fn print_alloc_error() { let mut pool = Pool::>::new(1..4); let sp = pool.subpool(5); assert_eq!(sp.unwrap_err(), AllocError::SizeNotAvailable(5i16)); let sp = pool.subpool(5); println!("kkk {}", sp.unwrap_err()); let sp = pool.subpool(5); assert_eq!( format!("{}", sp.unwrap_err()), "not enough Id's in allocator to allocate 5 Id's" ); } #[test] fn source_alloc_error() { let mut pool = Pool::>::new(1..4); let sp = pool.subpool(5); let e: &dyn std::error::Error = &sp.unwrap_err(); assert!(e.source().is_none()); }