aboutsummaryrefslogtreecommitdiffstats
path: root/todolist
diff options
context:
space:
mode:
Diffstat (limited to 'todolist')
-rw-r--r--todolist/filter.go7
-rw-r--r--todolist/filter_test.go13
2 files changed, 20 insertions, 0 deletions
diff --git a/todolist/filter.go b/todolist/filter.go
index 8c2a7ad..dd61d11 100644
--- a/todolist/filter.go
+++ b/todolist/filter.go
@@ -31,6 +31,13 @@ func (t *TodoFilter) isFilteringByContexts(input string) bool {
}
func (f *TodoFilter) filterArchived(input string) []*Todo {
+
+ // do not filter archived if want completed items
+ completedRegex, _ := regexp.Compile(`completed`)
+ if completedRegex.MatchString(input) {
+ return f.Todos
+ }
+
r, _ := regexp.Compile(`l archived$`)
if r.MatchString(input) {
return f.getArchived()
diff --git a/todolist/filter_test.go b/todolist/filter_test.go
index e4d3fed..c3bedbf 100644
--- a/todolist/filter_test.go
+++ b/todolist/filter_test.go
@@ -30,6 +30,19 @@ func TestFilterUnarchivedByDefault(t *testing.T) {
assert.Equal(false, unarchived[0].Archived)
}
+func TestFilterShowArchivedWhenWeAskForCompleted(t *testing.T) {
+ assert := assert.New(t)
+ store := &FileStore{FileLocation: "todos.json"}
+ list := &TodoList{}
+ todos, _ := store.Load()
+ list.Load(todos)
+ filter := NewFilter(list.Todos())
+ unarchived := filter.filterArchived("completed")
+ assert.Equal(2, len(unarchived))
+ assert.Equal(false, unarchived[0].Archived)
+ assert.Equal(true, unarchived[1].Archived)
+}
+
func TestGetArchived(t *testing.T) {
assert := assert.New(t)
store := &FileStore{FileLocation: "todos.json"}