diff options
| author | Grant Ammons <gammons@gmail.com> | 2017-05-25 09:56:02 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-25 09:56:02 -0400 |
| commit | e015094d20811d30676014d60d8219fa0fa63e8a (patch) | |
| tree | 5ba56e64e881cd0e0cdff4037033e5003d570c8c /todolist/parser_test.go | |
| parent | 6cb4a95af8bc4a8348c7b115fba334e668fe95e5 (diff) | |
| parent | f70fd56e6f2144f19150fb0fca2508a5897ab48b (diff) | |
Merge pull request #62 from gammons/unified-edit
Unified edit
Diffstat (limited to 'todolist/parser_test.go')
| -rw-r--r-- | todolist/parser_test.go | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/todolist/parser_test.go b/todolist/parser_test.go index 8cd6b53..f5cc185 100644 --- a/todolist/parser_test.go +++ b/todolist/parser_test.go @@ -169,3 +169,73 @@ func TestDueIntelligentlyChoosesCorrectYear(t *testing.T) { assert.Equal("2017-01-10", parser.parseArbitraryDate("jan 10", septemberTime)) assert.Equal("2017-01-10", parser.parseArbitraryDate("jan 10", decemberTime)) } + +func TestParseEditTodoJustDate(t *testing.T) { + assert := assert.New(t) + parser := &Parser{} + todo := NewTodo() + tomorrow := time.Now().AddDate(0, 0, 1).Format("2006-01-02") + + parser.ParseEditTodo(todo, "e 24 due tom") + + assert.Equal(todo.Due, tomorrow) +} + +func TestParseEditTodoJustDateDoesNotEditExistingSubject(t *testing.T) { + assert := assert.New(t) + parser := &Parser{} + todo := NewTodo() + todo.Subject = "pick up the trash" + tomorrow := time.Now().AddDate(0, 0, 1).Format("2006-01-02") + + parser.ParseEditTodo(todo, "e 24 due tom") + + assert.Equal(todo.Due, tomorrow) + assert.Equal(todo.Subject, "pick up the trash") +} + +func TestParseEditTodoJustSubject(t *testing.T) { + assert := assert.New(t) + parser := &Parser{} + todo := &Todo{Subject: "pick up the trash", Due: "2016-11-25"} + + parser.ParseEditTodo(todo, "e 24 changed the todo") + + assert.Equal(todo.Due, "2016-11-25") + assert.Equal(todo.Subject, "changed the todo") +} + +func TestParseEditTodoSubjectUpdatesProjectsAndContexts(t *testing.T) { + assert := assert.New(t) + parser := &Parser{} + todo := &Todo{ + Subject: "pick up the +trash with @dad", + Due: "2016-11-25", + Projects: []string{"trash"}, + Contexts: []string{"dad"}, + } + + parser.ParseEditTodo(todo, "e 24 get the +garbage with @mom") + + assert.Equal(todo.Due, "2016-11-25") + assert.Equal(todo.Subject, "get the +garbage with @mom") + assert.Equal(todo.Projects, []string{"garbage"}) + assert.Equal(todo.Contexts, []string{"mom"}) +} + +func TestParseEditTodoWithSubjectAndDue(t *testing.T) { + assert := assert.New(t) + parser := &Parser{} + todo := &Todo{ + Subject: "pick up the +trash with @dad", + Due: "2016-11-25", + Projects: []string{"trash"}, + Contexts: []string{"dad"}, + } + tomorrow := time.Now().AddDate(0, 0, 1).Format("2006-01-02") + + parser.ParseEditTodo(todo, "e 24 get the +garbage with @mom due tom") + + assert.Equal(todo.Due, tomorrow) + assert.Equal(todo.Subject, "get the +garbage with @mom") +} |
