From f9a98c7aa2d92b931c2ce34d188d9be390f4e2dc Mon Sep 17 00:00:00 2001 From: Quey-Liang Kao Date: Sun, 20 Aug 2017 23:04:29 +0800 Subject: Fix a bug in ParseNewTodo() The new pattern now does not allow empty todos to be added as "a" or "add" strings. --- todolist/parser.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'todolist') diff --git a/todolist/parser.go b/todolist/parser.go index cdfb179..d62c77d 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -12,7 +12,7 @@ import ( type Parser struct{} func (p *Parser) ParseNewTodo(input string) *Todo { - r, _ := regexp.Compile(`^(add|a)(\\ |) `) + r, _ := regexp.Compile(`^(add|a)(\s*|)`) input = r.ReplaceAllString(input, "") if input == "" { return nil -- cgit v1.3 From 0c2a2f99a9cdcc9acb7d55807330801d58d4c632 Mon Sep 17 00:00:00 2001 From: Quey-Liang Kao Date: Tue, 29 Aug 2017 17:19:11 +0800 Subject: Add test function TestAddEmptyTodo --- todolist/app_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'todolist') diff --git a/todolist/app_test.go b/todolist/app_test.go index 2fb7717..360da43 100644 --- a/todolist/app_test.go +++ b/todolist/app_test.go @@ -44,6 +44,18 @@ func TestAddTodoWithEuropeanDates(t *testing.T) { assert.Equal([]string{}, todo.Contexts) } +func TestAddEmptyTodo(t *testing.T) { + assert := assert.New(t) + app := &App{TodoList: &TodoList{}, TodoStore: &MemoryStore{}} + + app.AddTodo("a") + app.AddTodo("a ") + app.AddTodo("a\t\t\t\t") + app.AddTodo("a\t \t \t \t") + + assert.Equal(len(app.TodoList.Data), 0) +} + func TestListbyProject(t *testing.T) { assert := assert.New(t) app := &App{TodoList: &TodoList{}, TodoStore: &MemoryStore{}} -- cgit v1.3