error.rs (1298B)
1 #[cfg(feature = "std")] 2 use std::error::Error as _; 3 4 use radroots_core::{Error, Unit, currency, decimal, money, percent, pricing, quantity, unit}; 5 6 #[test] 7 fn aggregate_error_accepts_every_scoped_error() { 8 let errors = [ 9 Error::from(currency::ParseError::InvalidFormat), 10 Error::from(decimal::Error::ArithmeticOverflow), 11 Error::from(pricing::DiscountError::NegativeValue), 12 Error::from(money::Error::CurrencyMismatch), 13 Error::from(percent::ParseError::InvalidNumber), 14 Error::from(pricing::Error::PerQuantityZero), 15 Error::from(quantity::Error::UnitMismatch), 16 Error::from(unit::ParseError::UnknownUnit), 17 Error::from(unit::ConvertError::NotConvertibleUnits { 18 from: Unit::Each, 19 to: Unit::MassG, 20 }), 21 ]; 22 23 for error in errors { 24 #[cfg(feature = "std")] 25 assert!(error.source().is_some()); 26 assert!(!error.to_string().is_empty()); 27 } 28 } 29 30 #[test] 31 fn aggregate_error_display_identifies_the_owning_module() { 32 assert_eq!( 33 Error::from(decimal::Error::DivisionByZero).to_string(), 34 "decimal: decimal division by zero" 35 ); 36 assert_eq!( 37 Error::from(unit::ParseError::UnknownUnit).to_string(), 38 "unit parse: unknown unit string" 39 ); 40 }