diff --git a/src/parser.rs b/src/parser.rs index 6935c55..996b640 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -3,16 +3,13 @@ use regex::Regex; #[derive(Debug, PartialEq)] pub struct ParsedTask { pub title: String, - pub description: Option, pub priority: Option, } pub fn parse_task_input(input: &str) -> ParsedTask { let priority_re = Regex::new(r"!(\d+)\s*").unwrap(); - let description_re = Regex::new(r"\{([^}]*)\}").unwrap(); let mut priority = None; - let mut description = None; // Priority for caps in priority_re.captures_iter(input) { @@ -25,17 +22,7 @@ pub fn parse_task_input(input: &str) -> ParsedTask { } } - // Description - let mut title = input.to_string(); - if let Some(caps) = description_re.captures(&title) { - if let Some(desc_match) = caps.get(1) { - description = Some(desc_match.as_str().trim().to_string()); - } - } - - title = description_re.replace_all(&title, "").to_string(); - - title = priority_re.replace_all(&title, "").to_string(); + let title = priority_re.replace_all(&input, "").to_string(); let title = Regex::new(r"\s+") .unwrap() @@ -43,65 +30,13 @@ pub fn parse_task_input(input: &str) -> ParsedTask { .trim() .to_string(); - ParsedTask { - title, - priority, - description, - } + ParsedTask { title, priority } } #[cfg(test)] mod tests { use super::*; - #[test] - fn test_parse_with_description() { - let input = "Implement feature X {This is the description of the task}"; - let expected = ParsedTask { - title: "Implement feature X".to_string(), - description: Some("This is the description of the task".to_string()), - priority: None, - }; - let result = parse_task_input(input); - assert_eq!(result, expected); - } - - #[test] - fn test_parse_with_description_and_priority() { - let input = "Fix bug in module !2 {Critical issue that needs immediate attention}"; - let expected = ParsedTask { - title: "Fix bug in module".to_string(), - description: Some("Critical issue that needs immediate attention".to_string()), - priority: Some(2), - }; - let result = parse_task_input(input); - assert_eq!(result, expected); - } - - #[test] - fn test_parse_with_description_and_priority_in_any_order() { - let input = "{Detailed description here} Update documentation !3"; - let expected = ParsedTask { - title: "Update documentation".to_string(), - description: Some("Detailed description here".to_string()), - priority: Some(3), - }; - let result = parse_task_input(input); - assert_eq!(result, expected); - } - - #[test] - fn test_parse_with_multiple_descriptions() { - let input = "Task title {First description} {Second description}"; - let expected = ParsedTask { - title: "Task title".to_string(), - description: Some("First description".to_string()), - priority: None, - }; - let result = parse_task_input(input); - assert_eq!(result, expected); - } - #[test] fn test_parse_with_priority_in_middle() { let input = "Update !4 software documentation";