From dcca10afbb9ae9c132bc7bef4f89630bdddc7e7f Mon Sep 17 00:00:00 2001 From: Stuart Skelton Date: Wed, 2 Aug 2017 19:33:40 +0100 Subject: Do not filter out archived when asked for completed --- todolist/filter.go | 7 +++++++ todolist/filter_test.go | 13 +++++++++++++ 2 files changed, 20 insertions(+) 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"} -- cgit v1.3