From 3a1a7e855c505cef8a1e7983d20da4fd02d88566 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 8 Oct 2019 11:16:07 -0700 Subject: [PATCH] Add downcast_ref and downcast_mut tests --- tests/test_downcast.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/test_downcast.rs b/tests/test_downcast.rs index 3d7dc36..3b95931 100644 --- a/tests/test_downcast.rs +++ b/tests/test_downcast.rs @@ -22,3 +22,43 @@ fn test_downcast() { .to_string(), ); } + +#[test] +fn test_downcast_ref() { + assert_eq!( + "oh no!", + *bail_literal().unwrap_err().downcast_ref::<&str>().unwrap(), + ); + assert_eq!( + "oh no!", + bail_fmt().unwrap_err().downcast_ref::().unwrap(), + ); + assert_eq!( + "oh no!", + bail_error() + .unwrap_err() + .downcast_ref::() + .unwrap() + .to_string(), + ); +} + +#[test] +fn test_downcast_mut() { + assert_eq!( + "oh no!", + *bail_literal().unwrap_err().downcast_mut::<&str>().unwrap(), + ); + assert_eq!( + "oh no!", + bail_fmt().unwrap_err().downcast_mut::().unwrap(), + ); + assert_eq!( + "oh no!", + bail_error() + .unwrap_err() + .downcast_mut::() + .unwrap() + .to_string(), + ); +}