From 7bced94bddfa70417322112bd39c0126ce6b762c Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sat, 4 May 2024 21:10:35 +0200 Subject: [PATCH] test(src/types/newtypes): Test if a full round-trip works --- src/types/newtypes/mod.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/types/newtypes/mod.rs b/src/types/newtypes/mod.rs index 14873a9..2786e0e 100644 --- a/src/types/newtypes/mod.rs +++ b/src/types/newtypes/mod.rs @@ -108,3 +108,34 @@ impl Drop for String { } } } + +#[cfg(test)] +mod tests { + use crate::types::types_list; + + use super::String; + + #[test] + fn test_string_round_trip() { + let start = "HI! I'm a nice string".to_owned(); + let wrapper: String = start.clone().into(); + + assert_eq!(&start, wrapper.as_str()); + assert_eq!(start, wrapper.to_string()); + assert_eq!(start, wrapper.into_std_string()); + } + + #[test] + fn test_string_round_trip_through_c() { + let start = "HI! I'm a nice string".to_owned(); + + let c_string: types_list::String = start.clone().into(); + let wrapper: String = Into::::into(c_string) + .try_into() + .unwrap(); + + assert_eq!(&start, wrapper.as_str()); + assert_eq!(start, wrapper.to_string()); + assert_eq!(start, wrapper.into_std_string()); + } +}