From 31493968b56b8209067de793838e233930b614a2 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sat, 4 May 2024 21:10:35 +0200 Subject: [PATCH] tests(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()); + } +}