Compare commits
2 Commits
ddd620a021
...
fc7e45cd3f
| Author | SHA1 | Date |
|---|---|---|
|
|
fc7e45cd3f | |
|
|
9fe6ae5eb8 |
|
|
@ -17,6 +17,9 @@ pub struct Args {
|
|||
/// list closest files to date
|
||||
#[arg(short, long)]
|
||||
pub list: bool,
|
||||
/// number of files to list
|
||||
#[arg(short, long, default_value_t = 5)]
|
||||
pub number: usize,
|
||||
/// list closest files to date
|
||||
#[arg(short = 'L', long)]
|
||||
pub list_all: bool,
|
||||
|
|
|
|||
|
|
@ -111,3 +111,101 @@ pub fn extract_secitons<'a>(
|
|||
}
|
||||
groups
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::todo::Task;
|
||||
|
||||
#[test]
|
||||
fn test_extract_sections() {
|
||||
let test_md = "\
|
||||
# Test
|
||||
## Content
|
||||
- [ ] something
|
||||
- [x] done
|
||||
- [!] other
|
||||
## Unused
|
||||
### Sub section
|
||||
- [ ] task
|
||||
## Unrealated Stuff
|
||||
- [ ] something else
|
||||
+ [ ] subtask";
|
||||
|
||||
let arena = Arena::new();
|
||||
let root = parse_todo_file(&test_md.to_string(), &arena);
|
||||
|
||||
let result = extract_secitons(root, &vec![]);
|
||||
assert_eq!(result.keys().count(), 0);
|
||||
|
||||
let result = extract_secitons(root, &vec!["Not There".to_string()]);
|
||||
assert_eq!(result.keys().count(), 0);
|
||||
|
||||
let sections = vec!["Unused".to_string()];
|
||||
let result = extract_secitons(root, §ions);
|
||||
assert_eq!(result.keys().count(), 0);
|
||||
|
||||
let sections = vec!["Sub section".to_string()];
|
||||
let result = extract_secitons(root, §ions);
|
||||
println!("{:#?}", root);
|
||||
assert_eq!(result.keys().count(), 1);
|
||||
assert!(result.get(sections.first().unwrap()).is_some());
|
||||
assert_eq!(result.get(sections.first().unwrap()).unwrap().level, 3);
|
||||
|
||||
let sections = vec!["Content".to_string()];
|
||||
let result = extract_secitons(root, §ions);
|
||||
println!("{:#?}", root);
|
||||
assert_eq!(result.keys().count(), 1);
|
||||
assert!(result.get(sections.first().unwrap()).is_some());
|
||||
assert_eq!(
|
||||
result
|
||||
.get(sections.first().unwrap())
|
||||
.expect("No Value for \"Content\""),
|
||||
&TaskGroup {
|
||||
name: sections.first().unwrap().clone(),
|
||||
tasks: vec![
|
||||
Task {
|
||||
status: TaskStatus::Empty,
|
||||
text: "something".to_string(),
|
||||
subtasks: None
|
||||
},
|
||||
Task {
|
||||
status: TaskStatus::Todo('!'),
|
||||
text: "other".to_string(),
|
||||
subtasks: None
|
||||
},
|
||||
],
|
||||
level: 2
|
||||
}
|
||||
);
|
||||
|
||||
let sections = vec!["Unrealated Stuff".to_string()];
|
||||
let result = extract_secitons(root, §ions);
|
||||
assert_eq!(result.keys().count(), 1);
|
||||
assert!(result.get(sections.first().unwrap()).is_some());
|
||||
assert_eq!(
|
||||
result
|
||||
.get(sections.first().unwrap())
|
||||
.expect("No Value for \"Content\""),
|
||||
&TaskGroup {
|
||||
name: sections.first().unwrap().clone(),
|
||||
tasks: vec![Task {
|
||||
status: TaskStatus::Empty,
|
||||
text: "something else".to_string(),
|
||||
subtasks: Some(vec![Task {
|
||||
status: TaskStatus::Empty,
|
||||
text: "subtask".to_string(),
|
||||
subtasks: None
|
||||
}]),
|
||||
}],
|
||||
level: 2
|
||||
}
|
||||
);
|
||||
|
||||
let result = extract_secitons(
|
||||
root,
|
||||
&vec!["Content".to_string(), "Sub section".to_string()],
|
||||
);
|
||||
assert_eq!(result.keys().count(), 2);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,11 @@ fn main() {
|
|||
|
||||
let today = Local::now().date_naive();
|
||||
let target = today - TimeDelta::try_days(args.previous.into()).unwrap();
|
||||
let closest_files = TodoFile::get_closest_files(files.collect(), target, 5);
|
||||
if args.list_all {
|
||||
files.for_each(|f| println!("{}", f.canonicalize().unwrap().to_string_lossy()));
|
||||
return ();
|
||||
}
|
||||
let closest_files = TodoFile::get_closest_files(files.collect(), target, args.number);
|
||||
if args.list {
|
||||
closest_files
|
||||
.into_iter()
|
||||
|
|
|
|||
|
|
@ -2,5 +2,4 @@ mod file;
|
|||
mod tasks;
|
||||
|
||||
pub use file::File;
|
||||
pub use tasks::{Status, TaskGroup};
|
||||
|
||||
pub use tasks::{Status, Task, TaskGroup};
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::borrow::Borrow;
|
|||
use comrak::nodes::AstNode;
|
||||
use comrak::nodes::NodeValue;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct TaskGroup {
|
||||
pub name: String,
|
||||
pub tasks: Vec<Task>,
|
||||
|
|
@ -11,7 +11,7 @@ pub struct TaskGroup {
|
|||
}
|
||||
|
||||
// This does not support subtasks, need to figure out best path forward
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Task {
|
||||
pub status: Status,
|
||||
pub text: String,
|
||||
|
|
|
|||
Loading…
Reference in New Issue