Skip to content

Commit

Permalink
Merge pull request rust-lang#622 from lntuition/conversions_more_utc
Browse files Browse the repository at this point in the history
feat(conversions): Add more unit tests to `from_str` and `from_into` exercises.
  • Loading branch information
AbdouSeck authored Jan 8, 2021
2 parents 03d1434 + 6b9cec9 commit b3aed52
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions exercises/conversions/from_into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
12 changes: 12 additions & 0 deletions exercises/conversions/from_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,16 @@ mod tests {
fn missing_name_and_invalid_age() {
",one".parse::<Person>().unwrap();
}

#[test]
#[should_panic]
fn trailing_comma() {
"John,32,".parse::<Person>().unwrap();
}

#[test]
#[should_panic]
fn trailing_comma_and_some_string() {
"John,32,man".parse::<Person>().unwrap();
}
}

0 comments on commit b3aed52

Please sign in to comment.