1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
use serde::Deserialize;
/// 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, Copy, Debug, Eq, PartialEq, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Status {
Unknown,
Goal,
Finished,
Ready,
Next,
Blocked,
}
impl Default for Status {
fn default() -> Self {
Self::Unknown
}
}
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,
}
}
}
#[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);
}
}
|