diff options
| author | Grant Ammons <gammons@gmail.com> | 2017-05-09 20:17:33 -0400 |
|---|---|---|
| committer | Grant Ammons <gammons@gmail.com> | 2017-05-09 20:20:24 -0400 |
| commit | 580183ad7f155e4cdce047bdeb22fd775be69fc8 (patch) | |
| tree | 0f47692eff376539f1b6df52fc549246c177248f /todolist/parser_test.go | |
| parent | 423d2a238487c21ef36621bf93442c87504bfc7c (diff) | |
Update the tests
* Test editing a todo with just a due date does not affect subject
* Test editing a todo with just subject does not affect due date
* Editing a subject should also update projects and contexts
Diffstat (limited to 'todolist/parser_test.go')
| -rw-r--r-- | todolist/parser_test.go | 79 |
1 files changed, 54 insertions, 25 deletions
diff --git a/todolist/parser_test.go b/todolist/parser_test.go index 4466489..6920c7c 100644 --- a/todolist/parser_test.go +++ b/todolist/parser_test.go @@ -170,43 +170,72 @@ func TestDueIntelligentlyChoosesCorrectYear(t *testing.T) { assert.Equal("2017-01-10", parser.parseArbitraryDate("jan 10", decemberTime)) } -func TestParseCommandIdSubjectOptionalSubject(t *testing.T) { +func TestParseEditTodoJustDate(t *testing.T) { assert := assert.New(t) - parser := Parser{"d 24"} - command, id, subject := parser.Parse() + 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("d", command) - assert.Equal(24, id) - assert.Equal("", subject) + assert.Equal(todo.Due, tomorrow) + assert.Equal(todo.Subject, "pick up the trash") } -func TestParseCommandIdSubjectWhitespace(t *testing.T) { +func TestParseEditTodoJustSubject(t *testing.T) { assert := assert.New(t) - parser := Parser{"es 24\t a new subject"} - command, id, subject := parser.Parse() + parser := &Parser{} + todo := &Todo{Subject: "pick up the trash", Due: "2016-11-25"} + + parser.ParseEditTodo(todo, "e 24 changed the todo") - assert.Equal("es", command) - assert.Equal(24, id) - assert.Equal("a new subject", subject) + assert.Equal(todo.Due, "2016-11-25") + assert.Equal(todo.Subject, "changed the todo") } -func TestParseCommandIdSubject(t *testing.T) { +func TestParseEditTodoSubjectUpdatesProjectsAndContexts(t *testing.T) { assert := assert.New(t) - parser := Parser{"es 24 a new subject"} - command, id, subject := parser.Parse() + parser := &Parser{} + todo := &Todo{ + Subject: "pick up the +trash with @dad", + Due: "2016-11-25", + Projects: []string{"trash"}, + Contexts: []string{"dad"}, + } - assert.Equal("es", command) - assert.Equal(24, id) - assert.Equal("a new subject", subject) + 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 TestParseInvalidCommandIdSubject(t *testing.T) { +func TestParseEditTodoWithSubjectAndDue(t *testing.T) { assert := assert.New(t) - input := "es a new project" - parser := Parser{input} - command, id, subject := parser.Parse() + 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("", command) - assert.Equal(-1, id) - assert.Equal("", subject) + assert.Equal(todo.Due, tomorrow) + assert.Equal(todo.Subject, "get the +garbage with @mom") } |
