diff options
| author | Quey-Liang Kao <nonerkao@gmail.com> | 2017-07-07 23:46:53 +0800 |
|---|---|---|
| committer | Quey-Liang Kao <nonerkao@gmail.com> | 2017-07-07 23:46:53 +0800 |
| commit | df7cfd99feda5cf702790419b95a1bab59e50937 (patch) | |
| tree | d8745ee7d76b5124ca1a26736a9e9165d17d226d /todolist | |
| parent | 3d93d4ca4ff14bac3d4948995d33e11d83c33f80 (diff) | |
Improve logic and add a test
Diffstat (limited to 'todolist')
| -rw-r--r-- | todolist/date_filter.go | 5 | ||||
| -rw-r--r-- | todolist/date_filter_test.go | 19 |
2 files changed, 20 insertions, 4 deletions
diff --git a/todolist/date_filter.go b/todolist/date_filter.go index e876ba1..8d64484 100644 --- a/todolist/date_filter.go +++ b/todolist/date_filter.go @@ -57,10 +57,7 @@ func (f *DateFilter) filterAgenda(pivot time.Time) []*Todo { var ret []*Todo for _, todo := range f.Todos { - if todo.Due == "" { - continue - } - if todo.Completed { + if todo.Due == "" || todo.Completed { continue } dueTime, _ := time.ParseInLocation("2006-01-02", todo.Due, f.Location) diff --git a/todolist/date_filter_test.go b/todolist/date_filter_test.go index 444b4ac..6dd88f6 100644 --- a/todolist/date_filter_test.go +++ b/todolist/date_filter_test.go @@ -96,3 +96,22 @@ func TestFilterDay(t *testing.T) { assert.Equal(1, len(filtered)) assert.Equal(1, filtered[0].Id) } + +func TestFilterAgenda(t *testing.T) { + assert := assert.New(t) + + var todos []*Todo + + completedTodo := &Todo{Id: 1, Subject: "completed", Completed: true, Due: time.Now().Format("2006-01-02")} + uncompletedTodo := &Todo{Id: 2, Subject: "uncompleted", Due: time.Now().Format("2006-01-02")} + + todos = append(todos, completedTodo) + todos = append(todos, uncompletedTodo) + + filter := NewDateFilter(todos) + + filtered := filter.filterAgenda(time.Now()) + + assert.Equal(1, len(filtered)) + assert.Equal(2, filtered[0].Id) +} |
