diff options
| author | fmoko <mokou@posteo.de> | 2020-05-03 13:31:46 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-03 13:31:46 +0200 |
| commit | a39ffb2fb8ff334d6c292bfa6db8c16c42a1f4a9 (patch) | |
| tree | 20d6f01dbf6b45010e6112be7ddb1d4a8780785f /exercises/conversions/try_from_into.rs | |
| parent | ebfe76cdb69f67a2d81d51785992ad00e8ddbeda (diff) | |
| parent | 41f989135d79eba4602d4fde828698acf9a9f235 (diff) | |
Merge pull request #368 from apatniv/update_test_case
Diffstat (limited to 'exercises/conversions/try_from_into.rs')
| -rw-r--r-- | exercises/conversions/try_from_into.rs | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/exercises/conversions/try_from_into.rs b/exercises/conversions/try_from_into.rs index 834dd93..9968075 100644 --- a/exercises/conversions/try_from_into.rs +++ b/exercises/conversions/try_from_into.rs @@ -22,7 +22,8 @@ struct Person { // 1. If the length of the provided string is 0, then return an error // 2. Split the given string on the commas present in it // 3. Extract the first element from the split operation and use it as the name -// 4. Extract the other element from the split operation and parse it into a `usize` as the age +// 4. If the name is empty, then return an error. +// 5. Extract the other element from the split operation and parse it into a `usize` as the age // If while parsing the age, something goes wrong, then return an error // Otherwise, then return a Result of a Person object impl TryFrom<&str> for Person { @@ -68,4 +69,34 @@ mod tests { fn test_panic_bad_age() { let p = Person::try_from("Mark,twenty").unwrap(); } + + #[test] + #[should_panic] + fn test_missing_comma_and_age() { + let _: Person = "Mark".try_into().unwrap(); + } + + #[test] + #[should_panic] + fn test_missing_age() { + let _: Person = "Mark,".try_into().unwrap(); + } + + #[test] + #[should_panic] + fn test_missing_name() { + let _ : Person = ",1".try_into().unwrap(); + } + + #[test] + #[should_panic] + fn test_missing_name_and_age() { + let _: Person = ",".try_into().unwrap(); + } + + #[test] + #[should_panic] + fn test_missing_name_and_invalid_age() { + let _: Person = ",one".try_into().unwrap(); + } }
\ No newline at end of file |
