diff --git a/exercises/conversions/from_into.rs b/exercises/conversions/from_into.rs index f24cf61b..9d84174d 100644 --- a/exercises/conversions/from_into.rs +++ b/exercises/conversions/from_into.rs @@ -115,4 +115,18 @@ mod tests { assert_eq!(p.name, "John"); assert_eq!(p.age, 30); } + + #[test] + fn test_trailing_comma() { + let p: Person = Person::from("Mike,32,"); + assert_eq!(p.name, "John"); + assert_eq!(p.age, 30); + } + + #[test] + fn test_trailing_comma_and_some_string() { + let p: Person = Person::from("Mike,32,man"); + assert_eq!(p.name, "John"); + assert_eq!(p.age, 30); + } } diff --git a/exercises/conversions/from_str.rs b/exercises/conversions/from_str.rs index af9eee6d..70ed1796 100644 --- a/exercises/conversions/from_str.rs +++ b/exercises/conversions/from_str.rs @@ -82,4 +82,16 @@ mod tests { fn missing_name_and_invalid_age() { ",one".parse::().unwrap(); } + + #[test] + #[should_panic] + fn trailing_comma() { + "John,32,".parse::().unwrap(); + } + + #[test] + #[should_panic] + fn trailing_comma_and_some_string() { + "John,32,man".parse::().unwrap(); + } }