Skip to content

Commit b3aed52

Browse files
authored
Merge pull request rust-lang#622 from lntuition/conversions_more_utc
feat(conversions): Add more unit tests to `from_str` and `from_into` exercises.
2 parents 03d1434 + 6b9cec9 commit b3aed52

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

exercises/conversions/from_into.rs

+14
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,18 @@ mod tests {
115115
assert_eq!(p.name, "John");
116116
assert_eq!(p.age, 30);
117117
}
118+
119+
#[test]
120+
fn test_trailing_comma() {
121+
let p: Person = Person::from("Mike,32,");
122+
assert_eq!(p.name, "John");
123+
assert_eq!(p.age, 30);
124+
}
125+
126+
#[test]
127+
fn test_trailing_comma_and_some_string() {
128+
let p: Person = Person::from("Mike,32,man");
129+
assert_eq!(p.name, "John");
130+
assert_eq!(p.age, 30);
131+
}
118132
}

exercises/conversions/from_str.rs

+12
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,16 @@ mod tests {
8282
fn missing_name_and_invalid_age() {
8383
",one".parse::<Person>().unwrap();
8484
}
85+
86+
#[test]
87+
#[should_panic]
88+
fn trailing_comma() {
89+
"John,32,".parse::<Person>().unwrap();
90+
}
91+
92+
#[test]
93+
#[should_panic]
94+
fn trailing_comma_and_some_string() {
95+
"John,32,man".parse::<Person>().unwrap();
96+
}
8597
}

0 commit comments

Comments
 (0)