diff options
Diffstat (limited to 'todolist')
| -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") } |
