diff options
| author | Stuart Skelton <stuarts@broadbean.com> | 2017-08-02 19:33:40 +0100 |
|---|---|---|
| committer | Stuart Skelton <stuarts@broadbean.com> | 2017-08-02 19:33:40 +0100 |
| commit | dcca10afbb9ae9c132bc7bef4f89630bdddc7e7f (patch) | |
| tree | 5dd58f1949c4d33bb133c38714c73ad046dfa7ca | |
| parent | 5c574eb14ea782a27ff17dd4bd484dcb3803aae1 (diff) | |
Do not filter out archived when asked for completed
| -rw-r--r-- | todolist/filter.go | 7 | ||||
| -rw-r--r-- | todolist/filter_test.go | 13 |
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"} |
