From 03b84a88aeb9f3db000b5a9c795c172ad9fcbd51 Mon Sep 17 00:00:00 2001 From: Gustav Eek Date: Sun, 26 Feb 2023 21:18:54 +0100 Subject: [PATCH] Src. Ignore input with outdated priority Old outdated priority numbers is ignored in input. Function *winnow* is updated. Testing is completed as well. --- src/main.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 20eaf7d..5c0fe6b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,8 +18,9 @@ const DEBUG: bool = false; fn winnow(mut list: Vec) -> (Conf, Vec ) { list.retain(|x| x != ""); // only keep nonempty - // Search bullets + // Search patterns let bullet = Regex::new(r"^(\s*[\*-]\s*)").unwrap(); + let prio = Regex::new(r"^\s*[0-9]*\s*%\s*").unwrap(); let conf = Conf { bullet: match bullet.captures(&list[0]) { @@ -31,6 +32,7 @@ fn winnow(mut list: Vec) -> (Conf, Vec ) { // Remove patterns and trim for l in &mut *list { *l = bullet.replace_all(&l, "").to_string(); + *l = prio.replace_all(&l, "").to_string(); *l = l.trim().to_owned(); } list.retain(|x| x != ""); // again @@ -238,6 +240,20 @@ fn bullets() { #[test] +fn prioinput() { + let arg: Vec = + " - 70 % Hej du\n - 30 %\tglade\nta en\n" + .split("\n").map(|x| x.to_owned()) + .collect(); + let exp: Vec = + "Hej du\nglade\nta en" + .split("\n").map(|x| x.to_owned()).collect(); + let (_, res) = winnow(arg); + assert_eq!(exp, res); +} + +#[test] + fn bullout() { let conf = Conf {bullet: " * ".to_owned()}; let prio = vec![0.6, 0.3, 0.1]; -- 2.39.2