Skip to content

Commit

Permalink
Fixed todo note removing bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
nimaaskarian committed Jan 24, 2024
1 parent 06a0b13 commit 76a87ce
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 90 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "c3"
version = "0.3.2"
version = "0.3.3"
edition = "2021"

[dependencies]
Expand Down
17 changes: 13 additions & 4 deletions src/todo_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,21 @@ impl TodoList {
Ok(())
}

#[inline]
fn remove_dependencies(&mut self, path: &PathBuf) -> io::Result<()> {
let mut todos = [&mut self.undone.todos, &mut self.done.todos];
for todo in todos.iter_mut().flat_map(|v| v.iter_mut()) {
todo.remove_dependency(path);
}
Ok(())
}

#[inline]
fn handle_dependent_files(&mut self, path: &PathBuf) -> io::Result<()> {
let mut todos = [&mut self.undone.todos, &mut self.done.todos];
for todo in todos.iter_mut().flat_map(|v| v.iter_mut()) {
todo.dependency_write(path)?;
todo.remove_dependent_files()?;
todo.remove_dependent_files(path)?;
}
Ok(())
}
Expand Down Expand Up @@ -347,15 +356,15 @@ mod tests {
#[test]
fn test_todolist_read_undone() {
let todo_list = get_todo_list();
let expected_undone = vec![Todo::new("this todo has prio 1".to_string(), 1,false, None)
,Todo::new("this one has prio 2".to_string(), 2, false ,None)];
let expected_undone = vec![Todo::new("this todo has prio 1".to_string(), 1,false)
,Todo::new("this one has prio 2".to_string(), 2, false)];
assert_eq!(expected_undone, todo_list.undone.todos);
}

#[test]
fn test_todolist_read_done() {
let todo_list = get_todo_list();
let expected_done = vec![Todo::new("this one is 2 and done".to_string(), 2, true, None),Todo::new("this one is 0 and done".to_string(), 0, true, None)];
let expected_done = vec![Todo::new("this one is 2 and done".to_string(), 2, true),Todo::new("this one is 0 and done".to_string(), 0, true)];
assert_eq!(expected_done, todo_list.done.todos);
}

Expand Down
Loading

0 comments on commit 76a87ce

Please sign in to comment.