diff options
Diffstat (limited to 'src/status.rs')
-rw-r--r-- | src/status.rs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/status.rs b/src/status.rs new file mode 100644 index 0000000..247023c --- /dev/null +++ b/src/status.rs @@ -0,0 +1,65 @@ +/// Represent the status of a step in a roadmap. +/// +/// The unknown status allows the user to not specify the status, and +/// the roadmap to infer it from the structure of the graph. For +/// example, a step is inferred to be blocked if any of it +/// dependencies are not finished. + +#[derive(Clone,Debug,PartialEq)] +pub enum Status { + Unknown, + Goal, + Finished, + Ready, + Next, + Blocked, +} + +impl Status { + pub fn from_text(text: &str) -> Option<Status> { + match text { + "" => Some(Status::Unknown), + "goal" => Some(Status::Goal), + "finished" => Some(Status::Finished), + "ready" => Some(Status::Ready), + "next" => Some(Status::Next), + "blocked" => Some(Status::Blocked), + _ => None, + } + } +} + +impl PartialEq<Status> for &Status { + fn eq(&self, other: &Status) -> bool { + **self == *other + } +} + +impl PartialEq<&Status> for Status { + fn eq(&self, other: &&Status) -> bool { + **other == *self + } +} + + +#[cfg(test)] +mod test { + use super::Status; + + #[test] + fn happy_from_text() { + assert_eq!(Status::from_text("").unwrap(), Status::Unknown); + assert_eq!(Status::from_text("goal").unwrap(), Status::Goal); + assert_eq!(Status::from_text("finished").unwrap(), Status::Finished); + assert_eq!(Status::from_text("ready").unwrap(), Status::Ready); + assert_eq!(Status::from_text("next").unwrap(), Status::Next); + assert_eq!(Status::from_text("blocked").unwrap(), Status::Blocked); + } + + + #[test] + fn sad_from_text() { + let x = Status::from_text("x"); + assert_eq!(x, None); + } +} |