diff --git a/src/models.rs b/src/models.rs index d7cc1bf..7e42a3a 100644 --- a/src/models.rs +++ b/src/models.rs @@ -931,24 +931,52 @@ mod tests { } #[test] - fn test_to_from_option_string() { + fn test_to_option_string() { let s = "test".to_string(); assert_eq!(s.to_option_string(), Some("test")); let os: Option = Some("test".to_string()); assert_eq!(os.to_option_string(), Some("test")); - let mut s2 = "old".to_string(); - s2.set_from_option_string(Some("new".to_string())); - assert_eq!(s2, "new"); - s2.set_from_option_string(None); - assert_eq!(s2, "new"); - - let mut os2: Option = Some("old".to_string()); - os2.set_from_option_string(Some("new".to_string())); - assert_eq!(os2, Some("new".to_string())); - os2.set_from_option_string(None); - assert_eq!(os2, Some("new".to_string())); + let os_none: Option = None; + assert_eq!(os_none.to_option_string(), None); + } + + #[test] + fn test_from_option_string_for_string() { + let mut s = "old".to_string(); + + // Updating with Some should change the value + s.set_from_option_string(Some("new".to_string())); + assert_eq!(s, "new"); + + // Updating with None should keep the existing value + s.set_from_option_string(None); + assert_eq!(s, "new"); + } + + #[test] + fn test_from_option_string_for_option_string() { + let mut os: Option = Some("old".to_string()); + + // Updating with Some should change the value + os.set_from_option_string(Some("new".to_string())); + assert_eq!(os, Some("new".to_string())); + + // Updating with None should keep the existing value + os.set_from_option_string(None); + assert_eq!(os, Some("new".to_string())); + + let mut os_none: Option = None; + + // Updating None with Some should set the value + os_none.set_from_option_string(Some("init".to_string())); + assert_eq!(os_none, Some("init".to_string())); + + // Updating None with None should keep it None + let mut os_none2: Option = None; + os_none2.set_from_option_string(None); + assert_eq!(os_none2, None); } #[test]