use super::todo_priority::TodoPriority;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct TodoItem {
pub tag: String,
pub message: String,
pub line: usize,
pub column: usize,
#[serde(skip_serializing_if = "Option::is_none")]
pub line_content: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub author: Option<String>,
pub priority: TodoPriority,
}
impl TodoItem {
pub fn format_author(&self) -> String {
self.author
.as_ref()
.map(|a| format!("({})", a))
.unwrap_or_default()
}
}
#[cfg(test)]
mod tests {
use super::*;
fn item(author: Option<&str>) -> TodoItem {
TodoItem {
tag: "TODO".to_string(),
message: "test".to_string(),
line: 1,
column: 1,
line_content: None,
author: author.map(str::to_string),
priority: TodoPriority::Medium,
}
}
#[test]
fn format_author_wraps_in_parens_when_present() {
assert_eq!(item(Some("alice")).format_author(), "(alice)");
}
#[test]
fn format_author_is_empty_when_absent() {
assert_eq!(item(None).format_author(), "");
}
}