diff options
author | HampusM <hampus@hampusmat.com> | 2022-11-06 19:03:56 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-11-06 19:03:56 +0100 |
commit | 56349a530811bbf0657fed14912c7e02001b2c8a (patch) | |
tree | 165247000ceef0ceeaf3d0b7dbe48f9a6af10f29 /src/libs/intertrait/cast/arc.rs | |
parent | e282375de4ba75c69f7d619fc33c6250f6caba18 (diff) |
test: split up cast unit tests into their respective modules
Diffstat (limited to 'src/libs/intertrait/cast/arc.rs')
-rw-r--r-- | src/libs/intertrait/cast/arc.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/libs/intertrait/cast/arc.rs b/src/libs/intertrait/cast/arc.rs index 135cf64..6d3867c 100644 --- a/src/libs/intertrait/cast/arc.rs +++ b/src/libs/intertrait/cast/arc.rs @@ -45,3 +45,53 @@ impl<CastFromSelf: ?Sized + CastFromSync> CastArc for CastFromSelf }) } } + +#[cfg(test)] +mod tests +{ + use std::any::Any; + use std::fmt::{Debug, Display}; + use std::sync::Arc; + + use super::*; + use crate::test_utils::subjects; + + #[test] + fn can_cast_arc() + { + let concrete_ninja = Arc::new(subjects::Ninja); + + let abstract_ninja: Arc<dyn subjects::INinja> = concrete_ninja; + + let debug_ninja_result = abstract_ninja.cast::<dyn Debug>(); + + assert!(debug_ninja_result.is_ok()); + } + + #[test] + fn cannot_cast_arc_wrong() + { + let concrete_ninja = Arc::new(subjects::Ninja); + + let abstract_ninja: Arc<dyn subjects::INinja> = concrete_ninja; + + let display_ninja_result = abstract_ninja.cast::<dyn Display>(); + + assert!(matches!( + display_ninja_result, + Err(CastError::GetCasterFailed(_)) + )); + } + + #[test] + fn can_cast_arc_from_any() + { + let concrete_ninja = Arc::new(subjects::Ninja); + + let any_ninja: Arc<dyn Any + Send + Sync> = concrete_ninja; + + let debug_ninja_result = any_ninja.cast::<dyn Debug>(); + + assert!(debug_ninja_result.is_ok()); + } +} |