use strum_macros::Display to display Status

This commit is contained in:
Dustin J. Mitchell
2021-12-20 16:26:52 +00:00
parent 1bc7b5f019
commit 6a1d1a8c3c
2 changed files with 29 additions and 27 deletions

View File

@@ -274,7 +274,7 @@ mod tests {
uuid: t.get_uuid(), uuid: t.get_uuid(),
property: "status".into(), property: "status".into(),
old_value: None, old_value: None,
value: Some("P".into()), value: Some("pending".into()),
timestamp: now, timestamp: now,
}, },
ReplicaOp::Update { ReplicaOp::Update {
@@ -294,8 +294,8 @@ mod tests {
ReplicaOp::Update { ReplicaOp::Update {
uuid: t.get_uuid(), uuid: t.get_uuid(),
property: "status".into(), property: "status".into(),
old_value: Some("P".into()), old_value: Some("pending".into()),
value: Some("C".into()), value: Some("completed".into()),
timestamp: now, timestamp: now,
}, },
] ]

View File

@@ -1,5 +1,5 @@
/// The status of a task. The default status in "Pending". /// The status of a task. The default status in "Pending".
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone, strum_macros::Display)]
pub enum Status { pub enum Status {
Pending, Pending,
Completed, Completed,
@@ -11,9 +11,9 @@ impl Status {
/// defaulting to Pending /// defaulting to Pending
pub(crate) fn from_taskmap(s: &str) -> Status { pub(crate) fn from_taskmap(s: &str) -> Status {
match s { match s {
"P" => Status::Pending, "pending" => Status::Pending,
"C" => Status::Completed, "completed" => Status::Completed,
"D" => Status::Deleted, "deleted" => Status::Deleted,
_ => Status::Pending, _ => Status::Pending,
} }
} }
@@ -21,19 +21,9 @@ impl Status {
/// Get the 1-character value for this status to use in the TaskMap. /// Get the 1-character value for this status to use in the TaskMap.
pub(crate) fn to_taskmap(&self) -> &str { pub(crate) fn to_taskmap(&self) -> &str {
match self { match self {
Status::Pending => "P", Status::Pending => "pending",
Status::Completed => "C", Status::Completed => "completed",
Status::Deleted => "D", Status::Deleted => "deleted",
}
}
/// Get the full-name value for this status to use in the TaskMap.
pub fn to_string(&self) -> &str {
// TODO: should be impl Display
match self {
Status::Pending => "Pending",
Status::Completed => "Completed",
Status::Deleted => "Deleted",
} }
} }
} }
@@ -44,12 +34,24 @@ mod test {
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
#[test] #[test]
fn test_status() { fn to_taskmap() {
assert_eq!(Status::Pending.to_taskmap(), "P"); assert_eq!(Status::Pending.to_taskmap(), "pending");
assert_eq!(Status::Completed.to_taskmap(), "C"); assert_eq!(Status::Completed.to_taskmap(), "completed");
assert_eq!(Status::Deleted.to_taskmap(), "D"); assert_eq!(Status::Deleted.to_taskmap(), "deleted");
assert_eq!(Status::from_taskmap("P"), Status::Pending); }
assert_eq!(Status::from_taskmap("C"), Status::Completed);
assert_eq!(Status::from_taskmap("D"), Status::Deleted); #[test]
fn from_taskmap() {
assert_eq!(Status::from_taskmap("pending"), Status::Pending);
assert_eq!(Status::from_taskmap("completed"), Status::Completed);
assert_eq!(Status::from_taskmap("deleted"), Status::Deleted);
assert_eq!(Status::from_taskmap("something-else"), Status::Pending);
}
#[test]
fn display() {
assert_eq!(format!("{}", Status::Pending), "Pending");
assert_eq!(format!("{}", Status::Completed), "Completed");
assert_eq!(format!("{}", Status::Deleted), "Deleted");
} }
} }