initial commit
This commit is contained in:
39
exercises/05_ticket_v2/13_try_from/src/lib.rs
Normal file
39
exercises/05_ticket_v2/13_try_from/src/lib.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
// TODO: Implement `TryFrom<String>` and `TryFrom<&str>` for `Status`.
|
||||
// The parsing should be case-insensitive.
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
enum Status {
|
||||
ToDo,
|
||||
InProgress,
|
||||
Done,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
#[test]
|
||||
fn test_try_from_string() {
|
||||
let status = Status::try_from("ToDO".to_string()).unwrap();
|
||||
assert_eq!(status, Status::ToDo);
|
||||
|
||||
let status = Status::try_from("inproGress".to_string()).unwrap();
|
||||
assert_eq!(status, Status::InProgress);
|
||||
|
||||
let status = Status::try_from("Done".to_string()).unwrap();
|
||||
assert_eq!(status, Status::Done);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_try_from_str() {
|
||||
let status = Status::try_from("todo").unwrap();
|
||||
assert_eq!(status, Status::ToDo);
|
||||
|
||||
let status = Status::try_from("inprogress").unwrap();
|
||||
assert_eq!(status, Status::InProgress);
|
||||
|
||||
let status = Status::try_from("done").unwrap();
|
||||
assert_eq!(status, Status::Done);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user