diff options
author | Lars Wirzenius <liw@liw.fi> | 2019-09-28 10:31:50 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2019-09-28 11:36:36 +0300 |
commit | 6d4af8bd7fbfa88a7dd3820af2b557fe072a8311 (patch) | |
tree | c677aafd7fc44ffe763b2b25610bdfab0c059219 /src/status.rs | |
parent | 03b9822809b71fe302c83df2ddc832afd58777e0 (diff) | |
download | roadmap-6d4af8bd7fbfa88a7dd3820af2b557fe072a8311.tar.gz |
Change: move Status, Step, Roadmap, and parser to separate modules
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); + } +} |