fn winnow(mut list: Vec<String>) -> (Conf, Vec<String> ) {
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]) {
// 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
#[test]
+fn prioinput() {
+ let arg: Vec<String> =
+ " - 70 % Hej du\n - 30 %\tglade\nta en\n"
+ .split("\n").map(|x| x.to_owned())
+ .collect();
+ let exp: Vec<String> =
+ "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];