aboutsummaryrefslogtreecommitdiff
path: root/src/libs/intertrait/cast/box.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/intertrait/cast/box.rs')
-rw-r--r--src/libs/intertrait/cast/box.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/libs/intertrait/cast/box.rs b/src/libs/intertrait/cast/box.rs
index 67fd949..0e160f4 100644
--- a/src/libs/intertrait/cast/box.rs
+++ b/src/libs/intertrait/cast/box.rs
@@ -40,3 +40,52 @@ impl<CastFromSelf: ?Sized + CastFrom> CastBox for CastFromSelf
})
}
}
+
+#[cfg(test)]
+mod tests
+{
+ use std::any::Any;
+ use std::fmt::{Debug, Display};
+
+ use super::*;
+ use crate::test_utils::subjects;
+
+ #[test]
+ fn can_cast_box()
+ {
+ let concrete_ninja = Box::new(subjects::Ninja);
+
+ let abstract_ninja: Box<dyn subjects::INinja> = concrete_ninja;
+
+ let debug_ninja_result = abstract_ninja.cast::<dyn Debug>();
+
+ assert!(debug_ninja_result.is_ok());
+ }
+
+ #[test]
+ fn cannot_cast_box_wrong()
+ {
+ let concrete_ninja = Box::new(subjects::Ninja);
+
+ let abstract_ninja: Box<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_box_from_any()
+ {
+ let concrete_ninja = Box::new(subjects::Ninja);
+
+ let any_ninja: Box<dyn Any> = concrete_ninja;
+
+ let debug_ninja_result = any_ninja.cast::<dyn Debug>();
+
+ assert!(debug_ninja_result.is_ok());
+ }
+}