From 20c770843ff7969459349ee7fcc31a76434af43a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 10 Jul 2026 15:13:13 +0000 Subject: [PATCH] test(models): add comprehensive tests for FromOptionString trait - Refactor `test_to_from_option_string` into separate tests - Add `test_from_option_string_for_string` and `test_from_option_string_for_option_string` - Cover behavior of updating with Some and None values Co-authored-by: ffalcinelli <1167082+ffalcinelli@users.noreply.github.com> --- src/models.rs | 52 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 12 deletions(-) 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]