Skip to content

Commit

Permalink
add clean of single list; update Verison to 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
h4llow3En committed Apr 14, 2017
1 parent 0e74e25 commit e594b7a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tdo-core"
version = "0.1.0"
version = "0.1.1"
authors = ["Felix Döring <[email protected]>", "Felix Wittwer <[email protected]>"]
description = "The core of every Rust-based tdo application"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The core of every Rust-based tdo application.
```toml
#Cargo.toml
[dependencies]
tdo-core = "0.1.0"
tdo-core = "0.1.1"
```
## Documentation

Expand Down
10 changes: 10 additions & 0 deletions src/tdo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ impl Tdo {
}
}

/// Remove all todos that have been marked as _done_ from a given todo list.
pub fn clean_list(&mut self, list: &str) -> TdoResult<()>{
let index = match self.get_list_index(list){
Ok(index) => index,
Err(e) => return Err(e),
};
self.lists[index].clean();
Ok(())
}

fn get_list_index(&self, name: &str) -> TdoResult<usize> {
match self.lists
.iter()
Expand Down
21 changes: 19 additions & 2 deletions tests/done_remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod interact {
use tdo_core::{tdo, list, todo};

#[test]
fn clean_list() {
fn clean_lists() {
let mut tdo = tdo::Tdo::new();
tdo.add_list(list::TodoList::new("test")).unwrap();
tdo.add_todo(Some("test"), todo::Todo::new(0, "First Entry")).unwrap();
Expand All @@ -17,10 +17,27 @@ mod interact {
tdo2.add_todo(Some("test"), todo::Todo::new(1, "Second Entry")).unwrap();

tdo.lists[1].done_id(0).unwrap();
tdo.lists[1].clean();
tdo.clean_lists();
assert_eq!(tdo.lists[1].list.len(), tdo2.lists[1].list.len());
}

#[test]
fn clean_list() {
let mut tdo = tdo::Tdo::new();
tdo.add_list(list::TodoList::new("test")).unwrap();
tdo.add_todo(Some("test"), todo::Todo::new(0, "First Entry")).unwrap();
tdo.add_todo(Some("test"), todo::Todo::new(1, "Second Entry")).unwrap();
tdo.add_list(list::TodoList::new("test2")).unwrap();
tdo.add_todo(Some("test2"), todo::Todo::new(2, "First Entry")).unwrap();
tdo.add_todo(Some("test2"), todo::Todo::new(3, "Second Entry")).unwrap();

tdo.lists[1].done_id(0).unwrap();
tdo.lists[2].done_id(2).unwrap();
tdo.clean_list("test").unwrap();
assert_eq!(tdo.lists[1].list.len(), 1);
assert_eq!(tdo.lists[2].list.len(), 2);
}

#[test]
fn remove_from_list() {
let mut tdo = tdo::Tdo::new();
Expand Down

0 comments on commit e594b7a

Please sign in to comment.